When would be an appropriate time to delegate events with GWT using:
void com.google.gwt.user.client.ui.Widget.delegateEvent
Usually events dispatched by browser bubble up the node so I can't think of the reason why you would need to manually delegate the events.
A real use case would be great.
Thanks.
parent.delegateEvent(child, event) is actually the same as child.fireEvent(event).
fireEvent was originally a protected method so delegateEvent was added to expose it publicly (issue 3263), then fireEvent was made public as part of another change
It has nothing to do with the event delegation pattern.
Event delegation is especially useful in effects like dropdown menus, where lots of events on links may take place that can easily be handled at the root level (an or in this case).
Just go through the blog just written by . #Chris Heilmann and #Dan Webb with a use case demo
Related
Many tutorials and guides suggest that when you create a custom control in Xamarin.Forms or .NET MAUI with a ContentView (or extending another view), it should implement IDisposable interface when needed. See here and here.
That can be useful, as far as i can see, to unsubscribe from events.
My question is: when is Dispose() called?
I tried some scenarios in Xamarin.Forms involving moving from the page where the custom view lies and removing that page from the navigation stack, but none of these actions called the Dispose() method.
Do I have to call it manually?
Solution: Unsubscribe from the message in the message action/handler, or use a pattern of subscribing in OnAppearing and unsubscribing in OnDisappearing.
MessagingCenter.Subscribe<string, DetailClass>(this, "NavigateDetail", async (detail) =>
{
MessagingCenter.Unsubscribe<string>(this, "NavigateDetail");
await Naviation.PopAsync();
});
It seems you have to do it manually.
Javier Suarez answered this question with a Youtube comment under his video.
I want to get the list of all events for any particular component dynamically. For example : If I take a Textfield , how can I get all possible events that are mentioned in ExtJs API Doc. so that user can choose and assign the event for any component.
component.events
Contains the list you need. You could have found out by yourself reading the source of addEvents method, which is linked from any event you wanted to find in a list.
For those still wanting an answer to this, https://coderwall.com/p/jnqupq/easily-capture-all-events-on-a-component-in-extjs has provided a nice means of doing so.
When debugging an ExtJS application, you'll often find it useful to listen to all events fired by a specific component. There is actually a handy built-in static method to do this called Ext.util.Observable.capture().
Here's a handy snippet that simply logs the event name and all arguments:
Ext.util.Observable.capture(myObj, function(evname) {console.log(evname, arguments);})
Even better, if you're currently inspecting your component's main element in your browser's developer tools, you can do this:
Ext.util.Observable.capture(Ext.getCmp($0.id), function(evname) {console.log(evname, arguments);})
Where $0 is the currently selected element. Should work fine in Chrome, Firefox, Opera, Safari.
If you don't want those logs to pollute your console anymore, simply call releaseCapture on your object:
Ext.util.Observable.releaseCapture(myObj);
This removes all captures on a given object so you don't have to reference your listener explicitly (which was likely an anonymous function :)).
Bonus tip: also be sure to check out the observe method which does something similar but allows you to listen to all events fired by all instances of a given class.
I'm working on my first C#/WPF project (I'm a Java/Web developer with some Flex/As experience). The MVVM pattern seemed to be the way to go so I've started climbing the learning curve...
I'd like to know what's considered as the way to go to notify state modifications between related ViewModel objects.
Long story short, I have a UserControl containing a TreeView that is bound to a ReadOnlyCollection exposed by MyTreeViewModel.
SomethingViewModel implements INotifyPropertyChanged and generates an event when its 'IsSelected' property is changed.
MyTreeViewModel has an event handler attached to the PropertyChanged event of SomethingViewModel and updates a property that it manages called 'CurrentlySelectedElement'.
MyTreeViewModel also implements INotifyPropertyChanged and generates an event when its 'CurrentlySelectedElement' property changes.
Finally, I have an event handler in another ViewModel class that handles the selection change.
Is this a correct way of approaching this in C#/WPF?
Also, I'm not really fond of using property names with Strings in my event handling methods; It doesn't seem very refactoring friendly to me.. For now, I've dealt with this by exposing the property name as a static string, so that I can simply use the following in my event handler method:
if(SomeViewModel.PROPERTY_IS_SELECTED.Equals(e.PropertyName)) { ... }
Do you know a better alternative? I guess there should be a way of doing this but to be honest I didn't investigate that any further yet.
Thanks for your feedback!
Check out the Event Aggregator pattern. There are quite a few implementations out there. If you're using a MVVM framework ( https://stackoverflow.com/questions/1280462/what-mvvm-framework-are-you-using, What framework for MVVM should I use? ), chances are it will contain an implementation as well.
I'm working on an application which uses a List and some itemRenderers. I have a button displayed in the "selected" state automatically set by the List component. This button is supposed to dispatch a custom event when clicked. Problem is, I don't know how to add my event listener, and I don't want to use 'click=""' because it's kinda dirty IMHO.
/
If it was a SkinnableContainer, I could override the partAdded() but I couldn't find anything similar in the ItemRenderer or the DataRenderer.
Any hints?
Thanks !
You may use the button creationComplete event to add the listener.
Or, for complex itemRenderers I usually create my own that extends SkinnableComponent and implements IDataRenderer. You can then override partAdded/partRemoved functions. Note that you will also need to define and support the skin states (hovered, selected...).
In my GWT program I have a table that has a selected row. I'd like to move the row selection with the up- and down-keys on the keyboard. So I have to catch the key events somehow.
The GWT docs handle key events in input fields only. But I don't have an input field!
Is this possible at all? Maybe it is a DOM/Javascript restriction that GWT cannot work around...
It works by using Event.addNativePreviewHandler(NativePreviewHandler handler)
But there are some things to consider:
The handler is not restricted to a widget. It is global for your application. If you change widgets you might have to register and unregister the handler manually.
There are browser differences with keyboard events. Some browsers send keyDown- and keyPress-Events, others just keyDown-Events.
To work around the second issue you can get the name of the browser using this code:
private static native String getUserAgent() /*-{
return navigator.userAgent.toLowerCase();
}-*/;