Open ryneeverett opened 9 years ago
What's the use case? If we implement this, it's going to be a bit expensive, it'll require to traverse from every registered node upto the parent. Better avoid it if it does not add much value.
My use case is a less error-prone way of removing all handlers from the entire document
, but I could see where it could be useful for other elements.
I didn't think traversing would be necessary. Wouldn't it be possible to iterate over the EventsBucket
and check if each handler is a child of the selector?
My thinking is that in order to remove handlers from all (or a subset) of the DOM you need to keep track of the state of your handlers. Arrive is already keeping track of the state of your handlers so you shouldn't have to keep track of it separately. I guess another idea would be to just expose the state with a separate method like:
$('body').getArriveHandlers()
[<div class='.test-elem'></div>, <div class='.another-test-elem'></div>]
One could then iterate over them to remove them, but that method may have broader applications as well.
Oh, I didn't carefully read your comment.
it'll require to traverse from every registered node up to the parent
You're saying that even iterating over the EventsBucket
we'd still have to traverse all the way up the tree to find out if it's a child.
It seems like it would depend on the application whether the tradeoff is worth it -- the one-time cost of this traversal vs the cost of lingering handlers.
The one time cost is not much big of an issue here. The point that concerns me most is that if the use cases are common enough? Just don't want to add feature that are not used enough (they just increase size of library and don't add much value).
I use the library often but never felt the need for this. Lets see if someone is looking for the same feature.
I think we don't need to traverse, the matches function will serve the purpose. We already have a helper method for it utils.matchesSelector
in arrive.js
.
Hmm...no. It isn't useful in this case, we don't have a selector to match it against :)
Lets see if someone is looking for the same feature.
Agreed.
This is a proposal for an
unbindArrive
option:which would remove all bindings to
document
and it's children (meeting the selector/handler criteria).