Is it possible to get on Phoenix nested controllers? Like in remix.run, where for each route segment we get one controller/view. It’s really generalised version of layouts. When I was looking into Phoenix all routes, no matter how nested, had to resolve to single controller. That meant that controller for path `/user/settings/privacy` was also responsible for getting data to display users sidebar.
React to LiveView for Performance [audio]
41–48 of 48 posts
Re: React to LiveView for Performance [audio]
#42Earlier quoted context omitted.
LiveView and Elixir combine to in my opinion to make the only platform that's enjoyable for front end and backend developers. Front-end developers love the LiveView model with functional components, no state, and light node.js dependency. Backend developers get a process/actor + OTP supervision tree that's second to none. Horizontally scalable, functional, and pretty simple at its core. Fullstack developers get to tr…
> light node.js dependency Pedantic but just for drive-by readers, there isn't really any nodejs dependency. You can use it to manage JS dependencies, or you can forgo it for "vendoring" with esbuild (or bun, etc). Liveview itself has a small JS component that is mostly transparent (socket.connect() basically). You can of course add more JS too it.
Re: React to LiveView for Performance [audio]
#43Is it possible to get on Phoenix nested controllers? Like in remix.run, where for each route segment we get one controller/view. It’s really generalised version of layouts. When I was looking into Phoenix all routes, no matter how nested, had to resolve to single controller. That meant that controller for path `/user/settings/privacy` was also responsible for getting data to display users sidebar.
# lib/your_app_web/controllers/user_sidebar.ex
defmodule YourAppWeb.UserSidebar do
def load_sidebar(conn, _params) do
data = SomeModule.whatever_loads_your_sidebar_data()
assign(conn, :sidebar, data)
end
end
# then in router.ex:
import YourAppWeb.UserSidebar
pipeline :users do
plug :load_sidebar
end
scope "/users", YourAppWeb do
pipe_through [:browsers, :user]
get "settings/privacy", SettingsController, :privacy
# and all other routes that need this sidebar
# …
end
Then in your controller action `SettingsController.privacy/2`, the incoming `conn` will already have `sidebar` assigned because it's been passed through `load_sidebar`.Remember that an HTTP request/response cycle in Phoenix is fundamentally just a list of transformations that are applied to a `%Plug.Conn{}`. If you want the same behaviour to apply to multiple controller actions, you can just define that behaviour in a plug function (i.e. a two-arity function that takes and returns a conn), then pass your conn through that plug before it reaches your controller actions.
Re: React to LiveView for Performance [audio]
#44Earlier quoted context omitted.
Commercial grade apps where I do throttle CPU. If you are only re-rendering what is required, it's just a webpage at rest.
> If you are only re-rendering what is required, it's just a webpage at rest. As someone who has used React since 2015, and has worked on tons of React apps, with a wide range of team members and skill level, this is easier said than done. First of all, some developers just don't "get" React. The framework has a lot of foot guns, especially around performance. The most productive I've ever seen a team is with Mobx, w…
Re: React to LiveView for Performance [audio]
#45Earlier quoted context omitted.
If you're looking for something to do, implement this: https://www.deepmind.com/blog/decoupled-neural-interfaces-us... in this: https://hexdocs.pm/nx/Nx.html Someone at our local meetup said it was the future.
I’m experienced with Elixir but have no idea what all this is. Can you break it down for me and it’s benefits?
This lets you train a machine learning model of arbitrary size (bigger than can fit on a GPU, or even a multigpu node) using an actor-based distributed technique. There is a slight training cycles count penalty but it's way less than the cost of coordination.
Re: React to LiveView for Performance [audio]
#46Earlier quoted context omitted.
It is hard to justify, especially when front-end devs are monoglots. I bet your backend is Node + Mongo.
not just this, but also no one knows elixir. Its a very niche language for very niche set of tasks, rewriting existing apps form react to elixir just to use liveview is a pointless overkill
Re: React to LiveView for Performance [audio]
#47Re: React to LiveView for Performance [audio]
#48Is it possible to get on Phoenix nested controllers? Like in remix.run, where for each route segment we get one controller/view. It’s really generalised version of layouts. When I was looking into Phoenix all routes, no matter how nested, had to resolve to single controller. That meant that controller for path `/user/settings/privacy` was also responsible for getting data to display users sidebar.
Sounds like you want to define some shared behaviour that can be applied across a set of controllers? Phoenix doesn't have "nested" controllers like you describe, but you might be able to do what you want using a plug. Something like: # lib/your_app_web/controllers/user_sidebar.ex defmodule YourAppWeb.UserSidebar do def load_sidebar(conn, _params) do data = SomeModule.whatever_loads_your_sidebar_data() assign(conn, :…