proposal-signals icon indicating copy to clipboard operation
proposal-signals copied to clipboard

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

Open sorvell opened this issue 1 year ago • 4 comments

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

sorvell avatar Apr 09 '24 00:04 sorvell

Good catch! This should be deduplicated.

littledan avatar Apr 09 '24 01:04 littledan

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.

alxhub avatar Apr 09 '24 20:04 alxhub

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?

justinfagnani avatar Apr 09 '24 22:04 justinfagnani

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

alxhub avatar Apr 09 '24 23:04 alxhub