Skip to content

Refactor Emitter to use a Set for listeners#25

Open
nstadigs wants to merge 1 commit into
thejustinwalsh:mainfrom
nstadigs:listeners-as-set
Open

Refactor Emitter to use a Set for listeners#25
nstadigs wants to merge 1 commit into
thejustinwalsh:mainfrom
nstadigs:listeners-as-set

Conversation

@nstadigs

@nstadigs nstadigs commented Dec 29, 2025

Copy link
Copy Markdown

For constant time removals

Simpler alternative to #24.

@markerikson

Copy link
Copy Markdown
Contributor

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.

@nstadigs

Copy link
Copy Markdown
Author

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 😅

@captbaritone

Copy link
Copy Markdown
Collaborator

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?

@pkg-pr-new

pkg-pr-new Bot commented Jan 15, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/thejustinwalsh/react-concurrent-store@25

commit: b839ab2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants