I was inspired by the streaming mechanism from Elixir's liveview component
defmodule CounterComponent do
use Phoenix.LiveComponent
def render(assigns) do
~L"""
<div>
<h2>Counter: <%= @count %></h2>
<button phx-click="increment">Increment</button>
<button phx-click="decrement">Decrement</button>
</div>
"""
end
def mount(_session, socket) do
{:ok, assign(socket, count: 0)}
end
def handle_event("increment", _, socket) do
{:noreply, assign(socket, count: socket.assigns.count + 1)}
end
def handle_event("decrement", _, socket) do
{:noreply, assign(socket, count: socket.assigns.count - 1)}
end
end
and this will be used like this
<%= live_component @socket, CounterComponent, id: "counter" %>
In my opinion, this is a bit complicated way of working as the user needs to worry about sockets all the time.
We want to create an interface where the developer doesn't need to worry a lot about interacting with the websocket.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too