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

Watcher should be Disposable

Open DavidANeil opened this issue 1 year ago • 2 comments

A watcher should be easily disposable, without needing to track which signals it was previous watching. Using the (currently) stage 3 Symbol.dispose seems most appropriate.

Normative Spec Text

Method: Signal.subtle.Watcher.prototype[Symbol.dispose]()

  1. Invoke this.unwatch.apply(this, [[signals]])

DavidANeil avatar Apr 01 '24 20:04 DavidANeil

In the meantime, here's how you can do it with the current API:

watcher.unwatch(...Signal.subtle.introspectSources(watcher));

EisenbergEffect avatar Apr 01 '24 20:04 EisenbergEffect

Right, we could add this as a very small convenience, but it definitely doesn’t require any extra tracking to unwatch all sources, due to introspection. And you can look at the git history to see that we very recently did have such a Symbol.dispose method—I have gone back and forth in my thoughts on whether this is important.

littledan avatar Apr 01 '24 22:04 littledan