superchris

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 :wink:

As always, feedback is welcomed :slight_smile:

Most Liked

Eiji

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

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

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

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

arcyfelix

Oh, so it is for webcomponents.
Gotcha, thanks!

Where Next?

Popular in Libraries Top

mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
sabiwara
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code. You can try it out using this basic Elixir playground made ...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
engineeringdept
I’ve just released the first version of Snap, an Elasticsearch client. It borrows ideas about application structure and process managemen...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story &lt;- Meeseeks.all(html, css("tr.athing")) do...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
381 12391 119
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Sub Categories:

We're in Beta

About us Mission Statement