You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I'm working on won't be a SPA (at least not in the initial version). I want Rails to handle routing and rendering React components (with turbolinks). What I'm envisioning is a shared store approach and one route will have a couple of block components server side rendered which all get the store and that's where all app state is injected. I wanted this so to not mix app state through component props + store state, and keep data in a single place (this might not be the best way).
The problem
I'm not sure how to expose URLs from the rails app to the client. Of course the idea would be to have "prop serialisers" or "store state serialisers" computed in Rails that use the path helpers to expose all the component needs, but I imagine that there are subtle situations where this can get out of hand.
I mean, when you think about an isolated component props makes sense, but if the component that actually needs the URL is somewhere down the chain, you will want to but that in the store somehow so that you avoid the "big ball of props" from your top-level component. And if you want to put these URLs in the store you need to decide where they go. Dynamic URLs are resource related, that means that if you want to have a "resource" entry somewhere in the state tree you most probably have a resource serialiser that will include the URL, but then you're thinking, hmmm what if a page only cares about the URL for a small component, should I serialise the whole resource in the state tree to keep it consistent, or start hacking things around.
This was a bit of a brain dump sort of description, so I hope it isn't too hard to follow but what I'm after is basically is to see how other people are handling this.
The text was updated successfully, but these errors were encountered:
For anyone else that comes looking for this, I wanted to mention an alternative I found.
There's a gem called js-routes that is purpose-built for exposing Rails routes in JS. Unfortunately, it doesn't (yet) support webpacker out of the box, but there's an easy workaround here.
Context
What I'm working on won't be a SPA (at least not in the initial version). I want Rails to handle routing and rendering React components (with turbolinks). What I'm envisioning is a shared store approach and one route will have a couple of block components server side rendered which all get the store and that's where all app state is injected. I wanted this so to not mix app state through component props + store state, and keep data in a single place (this might not be the best way).
The problem
I'm not sure how to expose URLs from the rails app to the client. Of course the idea would be to have "prop serialisers" or "store state serialisers" computed in Rails that use the path helpers to expose all the component needs, but I imagine that there are subtle situations where this can get out of hand.
I mean, when you think about an isolated component props makes sense, but if the component that actually needs the URL is somewhere down the chain, you will want to but that in the store somehow so that you avoid the "big ball of props" from your top-level component. And if you want to put these URLs in the store you need to decide where they go. Dynamic URLs are resource related, that means that if you want to have a "resource" entry somewhere in the state tree you most probably have a resource serialiser that will include the URL, but then you're thinking, hmmm what if a page only cares about the URL for a small component, should I serialise the whole resource in the state tree to keep it consistent, or start hacking things around.
This was a bit of a brain dump sort of description, so I hope it isn't too hard to follow but what I'm after is basically is to see how other people are handling this.
The text was updated successfully, but these errors were encountered: