Hello, currently, to call send_update, i have to pass destination module and id (which is more of an html id than elixir side id - at least how i interpret it).
If i have live_component nested in another live component i do this currently
# Parent
<.live_component
module={ChildComponent}
id={"#{id}-child"}
parent={{__MODULE__, id}}
/>
# Child
def handle_event("...", _, socket) do
{parent_module, parent_id} = socket.assigns.parent
send_update(parent_module, id: parent_id, action: my_payload)
end
I looked under the hood and all parent_module, id: parent_id
does is gets cid to call further call correct callback (found by cid).
Wouldn’t it be easier just to
# Parent
<.live_component
module={ChildComponent}
parent={@myself}
/>
# Child
def handle_event("...", _, socket) do
send_update(socket.assigns.parent, action: my_payload)
end
- if no id is given cid is used as id
- both live views and live components have cid
- cid can be used to call send_update to any target (both live views and live components).
- live views might aswell have update callback to handle those cases.
This also would move towards implementing this this:Provide a unified mechanism to message the parent/child · Issue #1597 · phoenixframework/phoenix_live_view · GitHub