akre54 / Backbone.NativeView

A reference implementation of a native Backbone.View
MIT License
113 stars 18 forks source link

Undelegating differs from jQuery #19

Open akre54 opened 9 years ago

akre54 commented 9 years ago

While messing with NativeView#undelegate I realized that it's only possible to undelegate using a selector when that selector matches exactly the string passed to delegate. It doesn't do matching or sub-selections.

Let's say you called view.delegate('click', '*') and then tried to view.undelegate('click', 'div'). Or view.delegate('click', 'h1, div'), or any sub-selector. Since the strings don't match, we wouldn't be able to undelegate for you. Selector strings don't work that way.

I'm tempted to say "screw it". Undelegating isn't that common of a use case. We'd have to implement the better part of Sizzle to get this behavior (or call matches over a querySelectorAll ElementList). Is it worth solving?

mbrevda commented 9 years ago

I'm new to NativeView, so I don't have first hand experience (yet), but I would suppose you're correct: delegate() is probably most commonly used by remove(), which will use specific selectors. Additionally, the user-base of NativeView are probably those looking for a fine grained experience - not those looking for the comfort and hand-holding of jquery.