tc39 / proposal-signals

A proposal to add signals to JavaScript.
MIT License
3.4k stars 58 forks source link

Is there type constraint for the State? e.g. nested State? #109

Open leonyu opened 7 months ago

leonyu commented 7 months ago

Is there type constraint for the state/value? Conceivably state could be State<State<Foo>>. That should probably be documented.

This also begs the question whether Computed can perform filtering and higher-order functions (e.g. emit more times or less times than the source).

shaylew commented 7 months ago

First question: yes, no restrictions -- what constraints would you have expected?

Second question: I think this is a mistaken impression of how Computed works. They're not push based; they don't emit updated values eagerly, they just have a single up to date value (cached already, or recomputed as necessary) when read. So it doesn't really make sense to think of them as streams you can filter.

milomg commented 7 months ago

(Internally though, they can notify less by using the equality function, but never more)