tc39 / proposal-signals

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

Structured state based on signals #145

Open unadlib opened 1 month ago

unadlib commented 1 month ago

The proposal does not completely restrict signals to unstructured states, which implies that the encapsulation based on signals with proxy getters/setters might face two options in the future (relevant test cases are also mentioned here):

  1. Iterate through all properties, converting them into signals.
  2. Convert only the necessary properties into signals.

Both options have their pros and cons, but in practice, the second option might be more common. However, it could lead to consistency issues with signal judgments; whereas the first option could result in performance issues.

I am not sure if there is a better solution, but I believe this is a topic worth discussing.

unadlib commented 1 month ago

Additionally, this could impact the encapsulation of frameworks based on immutable data, such as in the use case within React. One of the most common scenarios is when I use signals for structured states (as in the second options), employing an API that uses proxy getters/setters with signals. In such cases, there might be unexpected redundant executions in APIs like 'computed'.

littledan commented 1 month ago

One thing to prove out with this signals API is that it is amenable to compound data structures. I am happy to see @NullVoxPopuli making progress with https://github.com/NullVoxPopuli/signal-utils/ and I would encourage others to either contribute there or try their own hand at the area. Maybe someday we should have a built-in signal-based object or array, but I would prefer to start with atoms, since they are complicated enough!

unadlib commented 2 weeks ago

Thank you for your response and for pointing me to @NullVoxPopuli's work on signal-utils. I agree that starting with atoms is a sensible approach given their complexity. However, as we move forward, I believe it's crucial to consider the implications of using signals with compound data structures early on. This will help us identify potential issues and solutions sooner rather than later.