Bubble up Flash from child liveview

How do I from a sticky child liveview, bubble up my put_flash to the containing liveview, so I can display flashes??

You can just send a message to the parent and handle it there:

# in child
pid = self() # or the pid of the parent, I use self since I used this tech in a LV component setup
send(pid, {:update_flash, :error, "foo"})

# in parent
def handle_info({:update_flash, type, msg}, socket) do
  {:noreply, put_flash(socket, type, msg)}
end

That doesn’t work for sticky liveviews though. The sticky LV is both a child LV of the root, but also has no root_pid, because it sticks around while the root LV changes.

You could do it via JS hooks I think but that feels hacky.

Ok, fair enough, I know nothing about sticky LiveView stuff :slight_smile: then you could send the message over pubsub. Bit more cumbersome bit I can image that would work.

I can parse down the parent pid and that way have a target