tc39 / proposal-signals

A proposal to add signals to JavaScript.
MIT License
2.87k stars 54 forks source link

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

Open prophile opened 2 weeks ago

prophile commented 2 weeks ago

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.