Refactor Emitter to use a Set for listeners#25
Conversation
For constant time removals
|
The one semantic question here is what happens if the same callback reference gets used more than once. I don't have a good example of when that might happen, just noting the behavior difference. |
Yeah, that's a thing indeed, but considering the "pureness" of react semantics any change in function scope should preferably result in a new function instance, no? I mean, in theory at least 😅 |
|
Thanks! I think I prefer this to the linked list, unless @markerikson has compelling data/annecdata indicating the linked list is significantly superior. That said, we do need to guard against the possibility of someone passing the same subscriber function more than once. We can enable this by adding back the wrapper function, or perhaps making the function a property of a specially created object. Can you also add a test which validates you can subscribe the same function twice and unsubscribe each subscription separately? |
commit: |
For constant time removals
Simpler alternative to #24.