superchris
Live-signals - LiveState backed signals for all of your signal needs (Phoenix Channels + Signals = LiveSignals)
Hey everybody, it seems like Signals are really catching on as a standard for reactivity in the front end space. Pretty much all the front end frameworks are adopting them, and they are also starting to make their way through the TC39 standards process. As an experiment, I decided to see how easy it would be to connect signals to a Pheonix Channel. Spoiler alert: it was really easy! I used LiveState (a thing I built) to hold the state for the signal.
The resulting library is: GitHub - launchscout/live-signals: LiveState backed signals for all of your signal needs
So far, preact signals and the TC39 polyfill are supported, but adding additional signal implementations should be trivial PRs I would be delighted to receive and merge ![]()
As always, feedback is welcomed ![]()
Most Liked
Eiji
This topic is a pure announcement. For Elixir or Phoenix it’s not a problem, but in this case lots of people may have no idea what Signals are. If you are one of them take a look at this article:
jswanner
I don’t think it’s a complete example (as onInput and onClick don’t seem to be used) but I think onClick in the following:
Shows how you can trigger events on the server:
Presumably, the state of the signal client-side will reflect what the server sent it, and the client uses dispatchEvent to call those server-side handlers.
superchris
I’ve added a little more to the preact example now. It’s not as fleshed out as the live-templates example I copied it from, but it works as far as showing how to dispatch event. Note that I have really know idea what I’m doing with Preact, so there is likely I more ideomatic preact approach. To your question @Sebb , as it seems like Signals are getting a reasonable amount of traction, using them to re-render state updates pushed down over a Phoenix Channel seems to be viable AFAICT. It really doesn’t change much: we are doing much the same with Lit Element based apps without signals, and it’s worked well for us.
Sebb
Say you implemented a webcomponent like
// this will tick up each second
customElement('my-counter', () => {
const [count, setCount] = createSignal(0);
setInterval(() => setCount(count() + 1), 1000);
return <div>Count: {count()}</div>;
})
and use this in your LV like
<my-counter id="counter_1"></my-counter>
You could just handle the state of the counter in LV-handle_info, or overwrite the count from the server. Without a bridge for the signals, you’d have to do that manually using events and hooks or such.
arcyfelix
Oh, so it is for webcomponents.
Gotcha, thanks!







