Hello all. I have a question as to best practices for code organization when implementing a liveview with a lot of responsibilities.
Supposing I have a section of an application that has a persistent interface with several different pages rendered in a main section of the page:
┌─────────────────┐
│ my_app_live.ex │
├─────────────────┴──────────────────────────────┐
│ Persistent UI │
├────────────────────────────────────────────────┤
│ │
│ │
│ ┌─────────────────────────────────────┐ │
│ │ │ │
│ │ │ │
│ │ Main body updating via @live_action │ │
│ │ (ie. pseudo router) │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ └─────────────────────────────────────┘ │
│ │
│ │
└────────────────────────────────────────────────┘
where the router might look like:
scope "/", MyAppWeb do
pipe_through :browser
live "/", MyAppLive, :home
live "/my-page", MyAppLive, :my_page
live "/authorize", MyAppLive, :authorize
end
and I want to isolate functionality so that I don’t have one gnarly live view. Specifically supposing I have a number of handle_params
that are unique to an individual subview.
What’s the best practice here? In my mind, I want to isolate the functionality of each subview within its own file. This seems very easy to do with live components, but it doesn’t really solve the issue of the callbacks unique to the subview.
Supposing the persistent UI had some kind of heavy data requirement that you wouldn’t want to trigger again and again on page navigation (and some of the data should be shared with the subviews as well), how would you go about tackling the problem while also keeping clear delineation of responsibilities (for easier maintenance, testing, etc.)