preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.71k stars 91 forks source link

Support SignalLike fro real #392

Closed artalar closed 1 year ago

artalar commented 1 year ago

I found that the signal public interface (SignalLike) is not actually used at runtime, but only for types. Under the hood, @preact/signals patches the runtime and does all the subscription and invalidation mechanics by itself based on its internal knowledge.

It would be awesome to support a signal version of React's useSyncExternalStore hook as a general interface for other state manager adapters.

export interface SignalLike<T> {
  peek(): T;
  subscribe(fn: (value: T) => void): () => void;
}
artalar commented 1 year ago

Moved to https://github.com/preactjs/preact/issues/4078