Re: [whatwg/dom] Removing event listeners through an identifier (#208)

@domenic 

> can you add an example of how this would be used? I'm also not sure on the best syntax, compared to the current proposal of { group: "string" }.

For example, let's say we have a UI library called Foobar. On events it adds, it could add two classes: one to identify the library (`foobar`) and one to identify the related set of actions (e.g. `foobar:edit`). It can use the second class to unbind all edit-related listeners and the first one when `.destroy()` is called, to quickly and easily unbind all library-related listeners. Also, even beyond this, sets of actions may overlap and often do. 

OTOH, I quickly went through the code of my Mavo framework and binding with more than 1 classes is less common as I remembered (though it does happen). It's however **extremely** common to **unbind** multiple classes at once.

>  I'm also not sure on the best syntax, compared to the current proposal of `{ group: "string" }`.

If restricted to strings, it could be a space-separated list, though that's very restrictive and it's unclear how it generalized to symbols. Using an iterable is probably a better solution, though strings would need to be special cased since they're also iterable. Or only specific iterables could be allowed, like arrays and sets.

Of course always keep the first rule of good API Design in mind: "Make the simple easy and the complex possible". It would be a hassle to require an array at all times just because in some cases multiple groups are needed. 

> again, an example would help. In #469 I added both removeEventListener("type", { group }) and removeEventListener({ group }), but I wasn't sure what the motivation was for the former; I just added it because it was very easy to do and fell out naturally from the design.

The motivation for the former is mainly removing a specific event listener without having to hold a reference to it which can often lead to really tangled code (think of cases where one method adds the listener and another method removes it — having to add a pointless property to the instance just to keep a reference to that listener is pretty ugly).

> The name is `group`, not `class` or `tag`.

Is there any particular reason why this is not negotiable?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/208#issuecomment-311182727

Received on Monday, 26 June 2017 21:10:21 UTC