dmitriid
Hi all
My go to pattern for handling data recently has been: have a Delete button on item. When user clicks the button, overlay the item with “Are you sure Yes/No”, and only delete the item when the user clicks “Yes”.
For non-streams this is easy.
socket
|> assign(a_list_of_items: items)
|> assign(requested_for_removal: nil)
# .... and then in a handle_event
socket |> assign(requested_for_removal: selected_item_id)
# .... and in heex
<div :for={ item <- @items}>
<div :if={ item.id != @requested_for_removal }>item data</div>
<div :if={ item.id == @requested_for_removal}>Are you sure? etc.</div>
</div>
For streams, however, this presents a bit of a problem. Since items are not retained in memory, I need to:
- fetch the item when
deleteis clicked - find its index in the stream
- update the stream at that position with data like “requested for removal”
- and if, for example, I want to only have one such overlay on page, I need to somehow remove it from a previous element
Has someone implemented something similar, and is there a better way?
Perhaps render hidden divs and show them with JS by toggling class names on elements?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
DaAnalyst
Yes, you could do it the way you suggest - have a hidden deletion element and toggle between the two.
rhcarvalho
This shouldn’t be necessary, because the stream helpers can update items in-place based on the item ID.
You could use that to update the state of the single stream entry with a
deletion_requested: true, causing the template for the item to re-render and a minimal diff be sent to the client.In fact this pattern would allow multiple items to be in this pending state simultaneously.
This also reminds me that probably you wouldn’t want to accidently re-add items to a stream during that event handler, or perhaps think about what’s the desired behavior - see stream_insert update_only aka stream_update by SteffenDE · Pull Request #3573 · phoenixframework/phoenix_live_view · GitHub & Add `stream_update` to LiveView Streams
dmitriid
However, in order to update the state of that entry I need to retrieve the full entry, and set
deletion_requested: trueon itSo far I’ve gone the JS route with a hidden element.