What I want to achieve
I am currently building a small frontend displaying a JavaScript based map, with markers for positions of assets. The map itself is a Component.
There are basically just two pages:
- An overview page listing all assets
- A detail page per asset.
I can update the map using push_event/3
, what works well on the details page:
There are two events, add_asset and update_asset.
On mounting the liveview, the asset is added to the map.
When new data comes (in my case in a handle_info), the asset position is updated.
I would like to add a map to the overview page, listing all assets positions.
What I tried to achieve this
As there already is a function to add an assets position to the map, I thought I’d just use that.
The overview page renders a bunch of Components, of which one is the map.
The other components are simply list entries, one per asset. All components are stateless.
I tried to push_event/3
an add_asset event from each components update()
callback.
Expected behaviour
I would have expected each asset to be added to the map.
Actual behaviour
Nothing is added.
Each attempt to add an asset should trigger a console.log(), but nothing is logged.
Question
Seems like the events are never actually pushed out to browser.
Does pushing events from within a components update() function not work?
Or maybe, do these occur before the socket connection is established?