Description
I've been working on a Rails app using React and Flux, and I've run into a few walls. I thought I would check with the react-rails community before I put my pioneer hat on.
So let me run through really quickly how I think I would like things to work, and maybe someone can let me know if I'm way off.
Serialization
This is not really a concern of react-rails, but it's important to my overall plan
I want all of my records for any given page serialized like so
{
posts: [
{
id: 1
title: "There's always money in the banana stand!",
body: "...",
author_id: 2,
comment_ids: [1]
}
],
comments: [
{
id: 1
author_id: 1,
body: "@gob you did mail that insurance letter, right?"
}
],
users: [
{
id: 1,
name: "Michael Bluth"
}, {
id: 2,
name: "George Bluth Sr."
}
]
}
In other words: I want each model serialized in an array on the root object. This will facilitate loading the models into their respective Flux stores.
Stores
I want all of my data loaded into stores, and then I want my react components to be passed those stores through properties. So rather than passing data directly into the component's properties, I want to tell react-rails which stores each component will need to access. My first thought was to abandon the react-rails UJS and just initialize my components the old fashioned way, but I realized it would be a pretty trivial thing to add into the UJS. This is what sparked the writing of this issue: I didn't know if this sounded like a good idea to anyone else, as I would be more than happy to submit a PR once it's all ready.
Server Side Rendering
I'm not sure at the moment how to get this all working with server side rendering. It's not a huge concern to me, but I realize that if this plan were to move forward at all with react-rails, there would need to be a way to get it to work with server side rendering.
My plan for getting the data into the stores was just going to be to pass them into gon and then have a script grab everything out of gon, and throw them into the stores. But gon wouldn't be available for server rendering, so I would need to work around that. But I don't see that as being too difficult of an issue.
Conclusion
If this sounds dumb, it's probably because it is. I haven't actually tried to do any of the following yet, but it's my tentative action plan. I would love to hear if anyone else has been successfully using the Flux architecture with react-rails, and what approach was taken. I would also be happy to begin working on a better integration for Flux and react-rails if anyone is interested in this approach (or a better one 😄).