-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Listeners to multiple components in ViewController #5
Comments
Below is a selector returning a group of items. Is there an equivalent way to do this inside a DeftJS ViewController?
|
That list item oriented use case is very compelling. Typically this would be solved by relying on event bubbling and listening to the parent component (the list) rather than creating listeners for each item. However, in your case you're interested in a particular child element within the list item. And, for the moment, you'd have to dispatch a unique event to differentiate between tap events for different buttons within a list item. I think there's room for improvement here. Thanks for reporting this issue. |
I see two different issues
I've been working on a patch to resolve both. Issue 1. could be fixed by
Issue 2. has two possible solutions. First possibility is to use event delegation (aka "live events") ala vanilla ExtJS 4 MVC. Can be implemented by overriding Ext.Component.fireEvent to dispatch the event to the appropriate ViewController instance that then executes all component queries live at event firing time rather than at controller instantiation time as it is now. Similarly getters/iterator functions would run queries live. Second solution is to automatically bind events to new components by listening to 'add' events for all containers controlled by the ViewController instance. When an 'add' event is fired just re-run all component queries against the newly added components and bind events (or create getters etc) for those that match. The first solution appears to have significantly better performance from my basic testing. As I don't want to duplicate effort I'm interested to know if you guys are already working on a patch for fixing these issues ? What approach do you think is best ? Is it worth me continuing to polish my patch to a state ready for a pull request ? I'll need to add some tests, fix some bugs, refactor it a little etc etc. I'm enjoying the DeftJS, awesome library =) Cheers |
Also if there are use-cases where you want to control a component that is not a child of a container from the same ViewController (e.g. a window?) I think an approach like #4 would still be needed in addition to all of the above. |
We're headed toward the 'live events' approach. As you noted, the automatic binding of all matching children based on 'add' is problematic and inefficient. We are leaning toward intercepting fireEvent(). I also agree that we would still want to include an approach for runtime registration and deregistration as in #4. So far the discussion around this issue and the changes necessary to support 'live events' has delayed resolution of #4 and inclusion of the pull request @wombelton so kindly provided. I'd definitely be intrigued to see your pull request - we might not use it verbatim but it will certainly influence the outcome. =) |
We are moving forward with the following solution:
Special thanks to @superstructor for making time to discuss this issue further and provide feedback and insight into his intended use cases. |
+1, this opt-in approach is a great idea. Thanks for the opportunity to provide feedback! |
I am still concerned about the performance hit associated with intercepting I am investigating an alternative implementation that hooks |
That approach is proving much more viable. Currently refactoring Deft.mvc.ViewController to accommodate a new |
The
Additionally, automatic getters generated from the This new feature is available in the code currently in the |
Reopening to address newly discovered Sencha Touch compatibility issues. |
I have a form that has two submit buttons, one in the upper right hand corner and another at the bottom.
Currently the only way to add a listener to both the buttons is to give it a unique identifier and create two separate listeners.
It'd be nice if there was a way to add a listener to both buttons using a single selector.
The text was updated successfully, but these errors were encountered: