bean icon indicating copy to clipboard operation
bean copied to clipboard

Undelegate doesn't work as advertised

Open beatgammit opened this issue 12 years ago • 5 comments

The API listed in the README is misleading. It says that I can do:

bean.undelegate(selector);

But calling this does absolutely nothing. On tracking it down, I found that delegate uses remove without any preprocessing. When I got to the remove function, it treated my selector as a an event. There was no logic differentiating a regular unbind (where the first element is an event name) and an undelegate.

beatgammit avatar Aug 24 '11 21:08 beatgammit

it's probably just advertised wrong... @fat?

ded avatar Aug 24 '11 22:08 ded

Well, delegate works correctly, so I'm guessing undelegate didn't get any love.

Right now, if I delegate something, then to remove listeners I remove them from the object, not the delegated object:

$(selector).delegate(selector2, event, handler);
$(selector).undelegate(event);

I would much prefer doing something like:

$(selector).undelegate(selector2, event);

beatgammit avatar Aug 24 '11 22:08 beatgammit

yeah -- $(selector).undelegate(selector2, event); isn't supported

fat avatar Aug 26 '11 00:08 fat

Right now I just remove the watches from the top-level element. That works for now, but it's not the most elegant solution.

Are there plans for supporting this? It kind of makes the 'undelegate' method useless, since it doesn't actually undelegate.

beatgammit avatar Aug 26 '11 03:08 beatgammit

Well, undelegate is just an alias for remove, much like delegate is an alias for add.

With delegation you're just filtering events in an event listener... but at it's root, it's really just a regular event.

If you want a cleaner way to add/remove these i highly recommend exploring namespaced events.

That said, I would be happy to take a pull request for this -- but the likely hood of me getting around to this (among all the ender and bootstrap opensource work i have on my plate right now) is fairly unlikely.

fat avatar Aug 26 '11 03:08 fat