proposal-signals
proposal-signals copied to clipboard
[polyfill] watching the same signal multiple times is not de-duplicated
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
Good catch! This should be deduplicated.
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.
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?
Ahh, watch definitely should (in the sense that you should ideally get one notification per signal being watched).