Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[polyfill] watching the same signal multiple times is not de-duplicated #157

Open
sorvell opened this issue Apr 9, 2024 · 4 comments · May be fixed by #191
Open

[polyfill] watching the same signal multiple times is not de-duplicated #157

sorvell opened this issue Apr 9, 2024 · 4 comments · May be fixed by #191

Comments

@sorvell
Copy link

sorvell commented Apr 9, 2024

I expected this to show 1 source, but it shows 2.

  watcher.watch(signal0);
  watcher.watch(signal0);
  console.log(Signal.subtle.introspectSources(watcher).length); // 2

Reproduction

@littledan
Copy link
Member

Good catch! This should be deduplicated.

@alxhub
Copy link
Collaborator

alxhub commented Apr 9, 2024

It's worth thinking about whether introspectSources should dedup automatically or not. I could see a perf argument that it's better to leave deduplication up to the consumer in the case that it's necessary.

@justinfagnani
Copy link
Collaborator

I think it's a footgun to not not deduplicate. I already wrote code that assumed watch() naturally would.

I think if watch() doesn't deduplicate, then the name should be changed to make it more obvious. Maybe addSignal() would convey that?

@alxhub
Copy link
Collaborator

alxhub commented Apr 9, 2024

Ahh, watch definitely should (in the sense that you should ideally get one notification per signal being watched).

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 a pull request may close this issue.

4 participants