Closed DaTrader closed 3 months ago
Your best bet in this case is use a hook which listeners for a dispatch from the stream item, like `phx-click={JS.dispatch("my-push,", detail: %{bar: @item_specific_assign})}, and within the and pushEvent yourself you merge the e.detail with whatever top level data you have. You could also have a hook per stream item that does the same thing, but reads and merges some parent info and skip the JS.dispatch. Propagating values would be doable, but it's highly specific to push, and JS.exec is about executing any JS chain, so I am not convinced it's what we want to do. Thanks!
Yes, doing it with a hook already and you're correct that what I suggest would be strongly related to JS.push
.
The use case is having a stream container with LiveComponent items whose
JS
on, sayphx-click
depends on an assign in the stream container LiveComponent. Being highly impractical to update all of the stream items only to propagate an update of such assign, it's convenient to have the items use aJS.exec
that executes a centralizedJS
command e.g. aJS.push
defined in a container LiveView/LiveComponent element.However, such centralized
JS.push
includes in its payload only the value parameters specified in its own element (thefoo
param in this case), which would otherwise be sufficient, but in this case it would be very convenient to be able to combine (merge) the value parameters of the item executing the centralizedJS
command as well (the 'bar` param in this case).Ex:
Stream container LiveView or LiveComponent:
Stream item LiveComponent:
Thanks!