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 Phoenix LiveView Crash Course - YouTube what guiding principles decide what ends up in (for instance) MemberSubscriptionLive.Index vs MemberSubscriptionLive.Edit.

1 Like

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 :man_shrugging:t2:

1 Like

Thank you for your input.

I guess I’ll have to determine it on a case-by-case basis. I’m not sure if LiveComponents make it easier or harder to determine what goes where…