Quetzakol
Hello! ![]()
I am playing a bit with Phoenix LiveView and Surface, and I’m struggling to find the right way to do a component.
Basically, I wanted to do a component with LiveComponent, that takes some text as a property. Then the component would display the text progressively, starting from a blank line and adding characters at a regular pace, like dialogs in video games.
Intuitively, I thought my stateful LiveComponent would be able to use Process.send_after and update the text being displayed in an handle_info. As it turns out, LiveComponents run in the process of their parent LiveView so I can’t do that. The only solution I found then is to handle that in the parent LiveView, but that means breaking the encapsulation as most of the component’s behaviour would not be handled by itself.
So I’m curious, how would you handle such a component?
Thanks for your help
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lud
This looks like a job for JavaScript.
preciz
I found these:
I hope these can be good starting points for you.
Qqwy
Alternatively this might mean it is time to transform this LiveComponent into its own LiveView process proper.
However, it seems like in this case you’re only trying to show an aesthetic effect. There are ways to do this kind of thing nowadays using only CSS I believe, which might be a better way to go, as it reduces network chatter and allows the browser to optimize animation. EDIT: Ah, @preciz already linked to some CSS resources just now
.
Quetzakol
The case I’ve given as an example does not really matter to me. I’m just playing with the lib.
Sure, I could use Javascript to do that, but I wanted to see how LiveView would be able to handle something like that by itself. After all, it’s often presented as a “you don’t have to write Javascript” solution.
I thought about that, but could not find a way to pass properties to it like I can do with a LiveComponent.
Basically, I’m surprised I can’t have a reusable and configurable component that is as dynamic as a LiveView process.
benwilson512
We’ve had similar real world situations (components subscribing to external information) and at the moment you simply can’t encapsulate it without using private Phoenix LiveView APIs. We just bit the bullet and have the parent live view do a handle_info to send_update.
However, I believe there are plans to allow
send_updateto work from external processes which would allow you to ping the component directly.Quetzakol
Thanks! That’s the kind of thing I was thinking I would want to do in the future. Too bad there is no better solution, but at least now I know I haven’t missed anything obvious.
Good to know, thanks
AndyL
I wrote a clock component, and ran into this self-updating issue too!
My solution also requires a
handle-infohandler in the parent LiveView…AndyL
I had another look at this, re-implemented as a LiveView, and everything is much simpler.