deadego

deadego

How to delete a specific stream from a socket?

Trying to drop a specific stream from a socket in LV via.

{_, socket} =
    pop_in(socket.assigns.streams[filter_string])

{_, socket} =
    pop_in(socket.assigns.streams.__configured__[filter_string])

{:noreply, socket}

But get

[error] GenServer #PID<0.1919.0> terminating
** (KeyError) key "test" not found in: %{__changed__: MapSet.new([]), __configured__: %{}, __ref__: 1}
    :erlang.map_get("test", %{__changed__: MapSet.new([]), __configured__: %{}, __ref__: 1})
    (elixir 1.18.3) lib/map.ex:318: Map.update!/3
    (phoenix_live_view 1.0.9) lib/phoenix_component.ex:1447: Phoenix.Component.update/3
    (phoenix_live_view 1.0.9) lib/phoenix_live_view/lifecycle.ex:223: anonymous fn/2 in Phoenix.LiveView.Lifecycle.after_render/1
    (phoenix_live_view 1.0.9) lib/phoenix_live_view/lifecycle.ex:237: Phoenix.LiveView.Lifecycle.reduce_socket/3
    (phoenix_live_view 1.0.9) lib/phoenix_live_view/lifecycle.ex:222: Phoenix.LiveView.Lifecycle.after_render/1
    (phoenix_live_view 1.0.9) lib/phoenix_live_view/channel.ex:992: anonymous fn/4 in Phoenix.LiveView.Channel.render_diff/3
    (telemetry 1.3.0) /home/dead/Dev/gale/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
    (phoenix_live_view 1.0.9) lib/phoenix_live_view/channel.ex:983: Phoenix.LiveView.Channel.render_diff/3
    (phoenix_live_view 1.0.9) lib/phoenix_live_view/channel.ex:819: Phoenix.LiveView.Channel.handle_changed/4
    (stdlib 6.2.2) gen_server.erl:2345: :gen_server.try_handle_info/3
    (stdlib 6.2.2) gen_server.erl:2433: :gen_server.handle_msg/6
    (stdlib 6.2.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Message{topic: "lv:phx-GDKJG9wvY7sfv3iB", event: "event", payload: %{"event" => "delete_filter", "type" => "click", "value" => %{"filter" => "test"}}, ref: "17", join_ref: "4"}
State: %{socket: #Phoenix.LiveView.Socket<id: "phx-GDKJG9wvY7sfv3iB", endpoint: GaleWeb.Endpoint, view: GaleWeb.HomePageLive, parent_pid: nil, root_pid: #PID<0.1919.0>, router: GaleWeb.Router, assigns: %{filters: ["test"], __changed__: %{}, current_user: #Gale.Users.User<__meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: "f08b5683-2009-4b58-8a09-105e2fddb5d0", email: "asdf@asdf.com", confirmed_at: nil, inserted_at: ~U[2025-04-01 01:47:38Z], updated_at: ~U[2025-04-01 01:47:38Z], ...>, flash: %{}, filter_form: %Phoenix.HTML.Form{source: #Ecto.Changeset<action: nil, changes: %{}, errors: [], data: %{}, valid?: true, ...>, impl: Phoenix.HTML.FormData.Ecto.Changeset, id: "form", name: "form", data: %{}, action: nil, hidden: [], params: %{}, errors: [], options: [method: "post"], index: nil}, streams: %{:__changed__ => MapSet.new([]), :__configured__ => %{"test" => [dom_id: #Function<0.13511000/1 in GaleWeb.HomePageLive.handle_event/3>]}, :__ref__ => 1, "test" => %Phoenix.LiveView.LiveStream{name: "test", dom_id: #Function<0.13511000/1 in GaleWeb.HomePageLive.handle_event/3>, ref: "0", inserts: [], deletes: [], reset?: false, consumable?: false}}, live_action: :home}, transport_pid: #PID<0.1908.0>, ...>, components: {%{}, %{}, 1}, topic: "lv:phx-GDKJG9wvY7sfv3iB", serializer: Phoenix.Socket.V2.JSONSerializer, join_ref: "4", redirect_count: 0, upload_names: %{}, upload_pids: %{}}
[

I assume there is a better way?

Most Liked

kokolegorille

kokolegorille

Maybe like this?

socket
|> stream(:mystream, [], reset: true)

But I don’t really understand what You are doing with your pop_in…

Last Post!

Therens

Therens

You can close the socket. You can’t remove streams. A multiplex socket is exactly that: a single socket with multiple streams coming through it.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement