I’ve been following the steps here for the upgrade from 1.6 to 1.7 and it has gone relatively smoothly all the way till the phoenix_view to phoenix_component switch. verified_routes are quite nifty.
In the past, I’ve found the liveview upgrades / breaking changes to be extremely valuable. I’m not quite sure about the phoenix changes though, but since I’m not sure phoenix_view will be deprecated in the future, I’m willing to put in the legwork to do the migration.
https://hexdocs.pm/phoenix_view/Phoenix.View.html#module-replaced-by-phoenix-component
To summarize for those considering the upgrade and all the layout changes:
- there is no views directory. Not sure where any functions are supposed to go that were in views.
- liveview templates are colocated in the liveview directory or embedded
- livecomponent templates are…I’m not sure where.
The two main issues I’m having are
- The templates for my LiveViews and LiveComponents are from 200-600 lines. These are far too large to embed into the render/1 function and I’m not sure how to pass on the assigns to the template.
Original
import AppWeb.ChartView
def render(assigns) do
AppWeb.ChartView.render("show.html", assigns)
end
New one where it’s not indicated how to pass the assigns into the
use AppWeb, :live_view
embed_templates "../templates/chart/*"
def render(assigns) do
# does not pass the assigns into the show and if they are passed as assigns={assigns} will need a template re-write
~H"""
<.show />
"""
end
I was hoping for something like the below code, but I cannot call render/2 or Phoenix.LiveView.render/2 because “(module Phoenix.Liveview is not available)”
def render(assigns) do
~H"""
<%= Phoenix.LiveView.render "show.html", assigns %>
"""
end
- I’ve put rendering specific functions into the views. App.ChartView has functions for making viewable dates, converting decimals to fractions, capitalization, etc.
I like the idea of getting rid of the views directory as it seemed like mostly boilerplate. However, I can’t figure out how to do an easy migration of the templates to use phoenix_component instead of phoenix_views.
I’m not understanding how to replace the render functions in a way that doesn’t require massive changes to the templates or how to pass in the helper functions for the view itself. What am I missing?