littlechat icon indicating copy to clipboard operation
littlechat copied to clipboard

Migrate HTML Data-Passing Hooks Pattern to LiveView v0.14's New `push_event` Function

Open JesseHerrick opened this issue 5 years ago • 2 comments

LiveView v0.14.0 added a new function, push_event/3 (docs), which allows us to push data from the server to the client's JS.

This solves an issue requiring a workaround in the original implementation of this app which required first creating a new HTML element in the LiveView with a dataset and JS hooks in order to pass data from the server to a client's JS. Since push_event/3 solves the problem (and should simplify and clean up the LiveView), let's implement it.

JesseHerrick avatar Aug 26 '20 13:08 JesseHerrick

+1

getting a ton of no DOM ID for hook "HandleIceCandidateOffer". Hooks require a unique ID on each element.

which leads to js breaking: eg TypeError: undefined is not an object (evaluating 'e.__trigger__')
(called here https://github.com/phoenixframework/phoenix_live_view/blob/931ff3cafee547635689d2557d752a500403fe46/assets/js/phoenix_live_view.js#L1622)

and the payloads doesn't seem to have unique ids making a quick fix difficult..

petermm avatar Sep 16 '20 20:09 petermm

Thanks for the heads up. We can just throw the index of the given assign’s element in as part of an ID for each generated element until we get a chance to switch over to using push_event.

JesseHerrick avatar Sep 17 '20 14:09 JesseHerrick