2

I read that signals are different from observables. But could one be used to implement the other? For example, could one implement Solid.js createSignal using the TC39 proposal? Would that be more efficient if it's native? Would it be even better to make a TC39 proposal for native Signal?

snnsnn
  • 10,486
  • 4
  • 39
  • 44
llllvvuu
  • 286
  • 1
  • 9
  • 1
    I don't see why people wants to close this because it has no focus. It is clear and well directed and technical, not an opinion based. – snnsnn Jul 17 '23 at 07:09

1 Answers1

1

Signals are different from observables as described in the proposal. The basic difference is that observables are event streams, so the listener receives an event that describes the change. Signals do not produce events; they simply notify the observers when their values change, and subscribers re-execute to get the new value. Observables use the pub/sub pattern, while signals use the observer pattern.

Solid's effect relies on re-execution for dynamic dependency tracking. Additionally, they receive the result of the previous execution, meaning it is not easy to fit the event streams without breaking the current implementation.

That being said, Solid provides two utility functions, observable and from, to integrate with external observable libraries like rxjs.

from creates a signal from an observable: https://www.solidjs.com/docs/latest/api#from

observable creates an observable from a signal: https://www.solidjs.com/docs/latest/api#observable

That proposal is unlikely to land because it does not address anything that cannot be achieved without native support.

snnsnn
  • 10,486
  • 4
  • 39
  • 44