Software:
- LiveView version
0.18.16
- Elixir
.1.14.1
I’m trying to figure out how to make the built-in table component update when some async data comes:
<pre>
<%= inspect(@job_remote_data) %>
</pre>
<.table id="jobs" rows={@streams.jobs}>
<:col :let={{_id, job}} label="Queue Size">
<%= inspect(@job_remote_data) %>
</:col>
</.table>
The problem is, the data in <:col>
gets out of sync with the live-view state. I’m not sure if that’s intended or a bug, but I want to forcefully re-render my column that’s showing @job_remote_data
%{"my_instance" => %{queues: %{in: 0, out: 0}}}
However, the same inspect lines a few lines down shows:
%{}
The data is being fetched like so:
def handle_info(:fetch_data, socket) do
result =
Remote.only_instance_nodes()
|> Enum.map(fn node -> {node, Remote.get_queues(node)} end)
|> Enum.map(fn {node, {:ok, in_size, out_size}} ->
{Remote.short_name(node), %{queues: %{in: in_size, out: out_size}}}
end)
|> Enum.into(%{})
IO.puts("RESULT IS: ")
IO.inspect(result)
{:noreply, socket |> assign(:job_remote_data, result)}
end
The results get fetched, the view re-renders, BUT the column that has a reference to this state remains stale, still shows the initial state of %{}
I was able to solve it by making a work-around, by using live-component here, but isn’t there a cleaner way to make this column update and be in sync?
I’m new to LiveView, coming from React, so I might be thinking of the whole “rendering” process in a biased way, and I don’t seem to understand how it works.
Thanks!