amarandon
Dear Elixir forum,
We have a web page in which we stream output from processing jobs. We’ve set up LiveView so that the content of our box reflects the current job output. It works great but we’d like to keep the job output in a fixed height box and always show the latest lines (unless the user scrolls up), similar to GitLab CI job output. We’ve got a pure CSS solution but unfortunately because of an old Firefox bug it works only on Chrome.
So we’re wondering if it’s possible to plug a small piece of JS code that would be called when LiveView triggers an update. We could use this code to scroll down the bottom of our output box whenever new content gets appended to it.
Another use case I’m thinking of for being able to call some custom JS code upon LiveView update is when adding items to a list, we could use a piece of JS to highlight the new item in order to make it more noticeable by the user.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 4 of 4 Posts
peerreynders
JS interop is an on-going effort.
So in case there isn’t a suggestion from anyone more familiar with LiveView forthcoming, it may be worthwhile to check out MutationObserver (as already suggested here) in order to run some client code in response to any changes in the DOM.
idi527
It’s also possible to listen for
"phx:update"events which are (at least to my knowledge) emitted when the DOM is done being patched.https://github.com/phoenixframework/phoenix_live_view/issues/81#issuecomment-473750152
I used it in some of my “experiments” with client side js libs (similarly to LiveView: How to trigger JS function? (Update chart.js on data change)) to create/destroy/recreate their objects when the DOM elements they were “bound” to got “morphdomed”.
peerreynders
Works with
thermostat_live.ex:Certainly simpler than using a
MutationObserver.amarandon
Thank you both. The
phx:updateevent did the trick for us. Many thanks.