derek-zhou
How do I send a unsolicited and generic event from the javascript side to the root LiveView, to be handled in handle_event/3? Do I have to use a Hook object attached to something, or is there a simpler way?
I was trying to do:
liveSocket.root.pushEvent(...)
But don’t know what to put in the parenthesis.
Also, How do I do the reverse, sending an generic event from the liveview to window or window.document object?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mindok
Hi @derek-zhou - have you read through the JS interop docs at JavaScript interoperability — Phoenix LiveView v1.2.5?
You will need hooks attached to an element in your liveview. The docs referenced above give an example of a hook setting up a listener for window events.
derek-zhou
I did. I can attach a hook to an element and achieve back and forth event. However, it feels awkward, because what I am doing has nothing to do with the element, or UI at all; I was just passing some data back and forth.
I was hoping since the
Phoenix.LiveViewis built on top of aPhoenix.Channel, I can use it to pass my sideband signals using the existing LiveView, without causing any harm to the LiveView.Ljzn
I’m using Vue as UI render in my LiveView project. It will call
Vue.createAppto render whole page every time when the html elements mounted or updated. (It’s not the best way but fast enough and simple).Then I can push event directly from vue components:
LostKobrakai
That‘s correct, but Liveview uses a custom handler on the client side. It uses the same infrastructure, but is more specialized than plain channels. So it doesn‘t necessarily do what plain channels do anymore.
derek-zhou
With a hook I can push_event from the server side and catch in the client side, and the reverse is also true. So I can achieve my goal with just a little detour. However, If I have a push_event followed by a push_redirect, the push_redirect will cull the earlier push_event, as documented in the doc at the very end. So my question is:
Do we have a guaranty that push_event themselves are handled in order? How about the other direction, from client to the server?
To get around the problem of push_redirect culling push_event, I am doing 2 push_events, the latter will trigger something like this:
So far with limited testing it seems to work well.
Miserlou
I’ve packaged a little utility library for interacting with the client JS context from LV - GitHub - Miserlou/live_json: LiveJSON - LiveView for JSON · GitHub
To send data to the server:
To send data to the client: