dberg
Organizing liveviews - when to use live_action, and when to have separate liveview?
I’ve seen a few posts discussing how to organize components, but what is best practice when it comes to organizing the liveviews themselves?
How much should I put in each liveview (and use @live_action) in the view to “toggle” whats shown, and when to break it out in a new liveview? Are there any example liveview projects that are more complex than say a todo-app - i.e something handling multiple nested “resources”?
For instance, it is not immediately clear to me when looking at the router (at 3:10) in https://youtu.be/SDDGOqPOHJ4?t=190 what guiding principles decide what ends up in (for instance) MemberSubscriptionLive.Index vs MemberSubscriptionLive.Edit.
Most Liked
RudManusachi
I don’t know if this is idiomatic, but the way I think of it is:
When it’s the same “view”, mostly the same page, but slightly modified, for example a component rendered with different params, or “toggled” to be shown or hidden at all as you suggested, but the event handlers and are mostly the same - I would use @live_action.
However, when, suppose, “Index” and “show” actions differ too much from each other and I find that too much of their logic get mixed in the same LiveView, then it’s probably a good idea to break it into separate LiveViews.
At first we could delegate handle_events to LiveComponents (phx-target={@myself}) but, for example handle_info is still need to be in parent LiveView ![]()
Popular in Questions
Other popular 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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









