You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using stickit in a Marionette Composite view, the outer instance of the view is seeing and honoring events from an inner view because the inner view's stickit's default updateModel() just returns true. If we change the default behavior to { event.stopPropagation(); return true; }, this problem goes away.
This isn't specific to Marionette - it's just an example where composed views get leakage of the events that stickit has already handled. Not that a coder couldn't override the newly-proposed default to restore earlier non-stopPropagation behavior if valuable.
The text was updated successfully, but these errors were encountered:
rjharmon
changed the title
When used in nested views, outer views should not recieve change-events that stickit has handled
When used in nested views, outer views should not receive change-events that stickit has handled
Jul 18, 2014
I don't really think this would be a good idea to do by default. There are many cases in which outer views depend on events bubbled up from inner views, even if some handler in those inner views has already responded. If a feature like this were to be implemented, I'd suggest that it would be best to do it as a flag in the binding config, like
// ...update: function($el,value){/* snip */},getVal: function($el){/* snip */},consumeEvents: true//default false}// end of binding config
Using stopPropagation() is almost always a bad idea.
It breaks a lot of things in unexpected ways, because there absolutely no way to know the event happened, should you need to. The most common example is some kind of menu, which you want to close if the user clicks outside of it. This is done by listening to click event bubbling from all over the DOM. If some handler calls stopPropagation(), the click will not reach the root and the menu will not close.
It breaks a developer's basic assumptions about events.
It can interact in some weird ways with third part libs, because they usually also assume events propagate normally.
One should use preventDefault() instead.
And if you need to prevent outer views from handling the events, have them check event.defaultPrevented (or event.isDefaultPrevented() if using jquery), and ignore the event if that's true.
Using stickit in a Marionette Composite view, the outer instance of the view is seeing and honoring events from an inner view because the inner view's stickit's default updateModel() just returns true. If we change the default behavior to { event.stopPropagation(); return true; }, this problem goes away.
This isn't specific to Marionette - it's just an example where composed views get leakage of the events that stickit has already handled. Not that a coder couldn't override the newly-proposed default to restore earlier non-stopPropagation behavior if valuable.
The text was updated successfully, but these errors were encountered: