I’ve just trying out LiveView for the first time, and I’ve generated a live endpoint with mix phx.gen.live TodoService Todo todos ...
, I have pulled in the generated routes to my routes file and it’s working.
Just to test things out, I tried rendering some HTML by editing the generated Heex, and it’s not working.
...
...
<ul
id="todos_list"
phx-update={match?(%Phoenix.LiveView.LiveStream{}, @rows) && "stream"}
>
<li
:for={{dom_id, todo} <- @streams.todos}
id={dom_id}
>
<span><%= todo.name %></span>
</li>
</ul>
<.table
id="todos"
rows={@streams.todos}
row_click={fn {_id, todo} -> JS.navigate(~p"/todos/#{todo}") end}
>
<:col :let={{_id, todo}} label="Name"><%= todo.name %></:col>
<:col :let={{_id, todo}} label="Notes"><%= todo.notes %></:col>
...
...
I’m getting the below error:
KeyError at GET /todos
`key :rows not found in: %{
socket: #Phoenix.LiveView.Socket<
id: "phx-F70FhIK4AoARkQvC",
endpoint: TodoAppWeb.Endpoint,
view: TodoAppWeb.TodoLive.Index,
parent_pid: nil,
root_pid: nil,
router: TodoAppWeb.Router,
assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>,
transport_pid: nil,
...
>,
__changed__: %{page_title: true, streams: true, todo: true},
flash: %{},
page_title: "Listing Todos",
live_action: :index,
streams: %{
__changed__: MapSet.new([:todos]),
todos: %Phoenix.LiveView.LiveStream{
name: :todos,
dom_id: #Function<3.112696910/1 in Phoenix.LiveView.LiveStream.new/4>,
ref: "0",
inserts: [
{"todos-3", -1,
%TodoApp.TodoService.Todo{
__meta__: #Ecto.Schema.Metadata<:loaded, "todos">,
id: 3,
name: "one",
notes: "one none",
is_completed: false,
is_archived: false,
inserted_at: ~U[2024-03-15 18:53:37Z],
updated_at: ~U[2024-03-15 18:53:37Z]
}, nil}
],
deletes: [],
reset?: false,
consumable?: false
},
__configured__: %{},
__ref__: 1
},
todo: nil
}`
Guess I can’t subscribe or use a stream more than twice in a View??
Can someone elaborate on how it works. The docs is silent on streams.