sezaru
LiveBulkAsync - A library to allow LV's async functionality in update_many function
LiveBulkAsync is a small library that extends LiveView’s async support to work with LiveComponent’s update_many function.
My main use case for it is to load columns data in a table asynchronously. Imagine that you have a table that contains a column which data takes time to load (maybe it is from an external API, or it is an expensive DB query).
Using LiveBulkAsync you can leverage LiveComponent’s update_many function to avoid N + 1 issues and still do the load without blocking the component.
The API tries to mimic the LV’s async API as much as possible and have the same guarantees.
Here’s the equivalent to start_async:
defmodule MyComponent do
@moduledoc false
use Phoenix.LiveComponent
def update_many(assigns_and_sockets) do
assigns_and_sockets
|> Enum.map(fn {assigns, socket} ->
socket |> assign(assigns) |> assign(loading?: true)
end)
|> start_many_async(:content, &load/0)
end
def handle_async(:content, {:ok, content}, socket) do
{:noreply, assign(socket, loading?: false, content: content)}
end
def handle_async(:content, {:exit, reason}, socket) do
{:noreply, socket}
end
def render(assigns) do
~H"""
<div id={@id}>
<div :if={@loading?}>loading...</div>
<div :if={not @loading?}>{@content}</div>
</div>
"""
end
defp load! do
# Load something here
["content 1", "content 2"]
end
end
And here’s the equivalent to assing_async:
defmodule MyComponent do
@moduledoc false
use Phoenix.LiveComponent
def update_many(assigns_and_sockets) do
assigns_and_sockets
|> Enum.map(fn {assigns, socket} ->
socket |> assign(assigns) |> assign(loading?: true)
end)
|> assign_many_async(:content, fn -> load!() end)
end
def render(assigns) do
~H"""
<div id={@id}>
<.async_result :let={content} assign={@content}>
<:loading>Loading...</:loading>
<:failed :let={reason}><pre>{inspect(reason)}</pre></:failed>
<div>{content}</div>
</.async_result>
</div>
"""
end
defp load! do
# Load something here
{:ok, %{content: ["content 1", "content 2"]}}
end
end
For more information you can check its repo or hex package.
Popular in Announcing
In short
Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
Hello everybody :wave:
Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New
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
Bandit is an HTTP server for Plug and WebSock apps.
Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
Hey everyone!
Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
Hey everyone!
Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
Hey everyone,
I just released WebSockex which is a Elixir WebSocket client.
WebSockex strives to work as a OTP special process, be RFC6...
New
Hello everyone!
I am excited to share our heart project Backpex with you.
After building several Phoenix applications, we realized that...
New
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
Other popular topics
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
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
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








