preactjs / signals

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

Detect a signal without tightly binding to a version of the library #402

Closed rictic closed 1 year ago

rictic commented 1 year ago

We're working on a way to write a Lit html template that will automatically handle signals. The core of the implementation is:

  values.map((v) => v instanceof Signal ? watch(v) : v)

However, this will not work properly if a user has multiple versions of @preact/signals-core in their node_modules tree, as it will only detect whatever version of Signal was imported in our library. Ideally, people wouldn't end up with multiple versions of signals in their node_modules of course, but in practice we find that users end up with multiple versions in their node_modules even within a single major version.

What we'd like is something like this to work:


const brand = Symbol.for('preact-signals');

...

   values.map((v) => v?.[brand] ? watch(v) : v)