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

Spell out ordering of `sources`/`sinks` sets

Open prophile opened this issue 1 year ago • 0 comments

I think it would be better to be very explicit here rather than relying on implicit reference to the ES Set, specifically: that sources and sinks aren't semantically sets but arrays/lists (intrinsically ordered), and that we explicitly check their contents and don't re-add anything. There's some ambiguity as it's currently worded:

In the Typescript definitions, there's a comment:

        // Returns ordered list of all signals which this one referenced
        // during the last time it was evaluated.
        // For a Watcher, lists the set of signals which it is watching.

But it doesn't specify what order, just that it is ordered. Specifically this is order of first reference I think. For a Watcher the order isn't specified at all here but probably should be?

In the "Signal.Computed Internal Slots" section also:

sources: An ordered set of Signals which this Signal depends on. sinks: An ordered set of Signals which depend on this Signal.

We should be clear about what this order is. This is more subtle because items can be individually removed, e.g. by Signal.subtle.Watcher.prototype.unwatch(...signals):

Remove this Watcher from that Signal's sink set.

If the same watcher calls watch on the same Signal.Computed it will be readded as a sink, but that leaves the order of sinks permuted from what it originally was.

prophile avatar Apr 29 '24 17:04 prophile