tc39 / proposal-signals

A proposal to add signals to JavaScript.
MIT License
3.45k stars 59 forks source link

Rational: why no effects out of the box? #242

Open NullVoxPopuli opened 1 month ago

NullVoxPopuli commented 1 month ago

We've had a number of issues about effects

The gist somewhat comes down to a difference in opinion of the necessity for effects. Also, there are different kinds of effects. In particular, in the js-reactivity-benchmark -- it can only test with synchronous effects -- see this issue on environments without such a concept maybe being unbenchable as a result (or at least, necessitates macro benching).

A summary (of what I can remember right now) of the stances:

justinfagnani commented 1 month ago

I think it'd be nice to expand on "effects require an ownership model", which I think is very tied into "effects should be run by a scheduler" (which is how I would summarize the first point).

Ownership is important because it would be used by the scheduler to order effects so that other side effects of changing state that naturally occur in ownership-tree-order are done in a coherent way. The main example being a UI component tree and needing to run component-associated effects in tree order so that parents render first, and if parents pass data to children that are also responding to signal changes, that the child only renders once.

This is my understand of the technical reason to prefer to push effects out to a library that would presumably also handle scheduling. Clarifying this might make the stance make more sense to some of the people who are asking for built-in effects. It might also outline what would be necessary to have either a good built-in effect, or some kind of hooks for scheduling effects.

justinfagnani commented 1 month ago

I'm not sure how to interpret 👎 on this issue. Are they asking to not state the rationale?

EisenbergEffect commented 1 month ago

I'm not sure either @justinfagnani. I think the request is more than reasonable. Unfortunately, I wasn't present when some of the discussion around this was happening, leading up to the initial proposal. Perhaps @milomg has some insights he can share.