Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a websocket based streaming mechanism #41

Open
sansyrox opened this issue Jun 2, 2023 · 0 comments
Open

Implement a websocket based streaming mechanism #41

sansyrox opened this issue Jun 2, 2023 · 0 comments

Comments

@sansyrox
Copy link
Member

sansyrox commented Jun 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant