{"action":"created","issue":{"url":"https://api.github.com/repos/reactjs/react-rails/issues/143","labels_url":"https://api.github.com/repos/reactjs/react-rails/issues/143/labels{/name}","comments_url":"https://api.github.com/repos/reactjs/react-rails/issues/143/comments","events_url":"https://api.github.com/repos/reactjs/react-rails/issues/143/events","html_url":"https://github.com/reactjs/react-rails/issues/143","id":53575156,"number":143,"title":"Better support for Flux architecture","user":{"login":"willcosgrove","id":77887,"avatar_url":"https://avatars.githubusercontent.com/u/77887?v=3","gravatar_id":"","url":"https://api.github.com/users/willcosgrove","html_url":"https://github.com/willcosgrove","followers_url":"https://api.github.com/users/willcosgrove/followers","following_url":"https://api.github.com/users/willcosgrove/following{/other_user}","gists_url":"https://api.github.com/users/willcosgrove/gists{/gist_id}","starred_url":"https://api.github.com/users/willcosgrove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willcosgrove/subscriptions","organizations_url":"https://api.github.com/users/willcosgrove/orgs","repos_url":"https://api.github.com/users/willcosgrove/repos","events_url":"https://api.github.com/users/willcosgrove/events{/privacy}","received_events_url":"https://api.github.com/users/willcosgrove/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-01-06T23:03:10Z","updated_at":"2015-01-19T02:14:39Z","closed_at":null,"body":"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.\r\n\r\nSo 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.\r\n\r\n## Serialization\r\n\r\n*This is not really a concern of react-rails, but it's important to my overall plan*\r\n\r\nI want all of my records for any given page serialized like so\r\n\r\n```js\r\n{\r\n  posts: [\r\n    {\r\n      id: 1\r\n      title: \"There's always money in the banana stand!\",\r\n      body: \"...\",\r\n      author_id: 2,\r\n      comment_ids: [1]\r\n    }\r\n  ],\r\n  comments: [\r\n    {\r\n      id: 1\r\n      author_id: 1,\r\n      body: \"@gob you did mail that insurance letter, right?\"\r\n    }\r\n  ],\r\n  users: [\r\n    {\r\n      id: 1,\r\n      name: \"Michael Bluth\"\r\n    }, {\r\n      id: 2,\r\n      name: \"George Bluth Sr.\"\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\nIn 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.\r\n\r\n## Stores\r\n\r\nI 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.\r\n\r\n## Server Side Rendering\r\n\r\nI'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.\r\n\r\nMy plan for getting the data into the stores was just going to be to pass them into [gon](https://github.com/gazay/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.\r\n\r\n## Conclusion\r\n\r\nIf 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 :smile:). "},"comment":{"url":"https://api.github.com/repos/reactjs/react-rails/issues/comments/70438730","html_url":"https://github.com/reactjs/react-rails/issues/143#issuecomment-70438730","issue_url":"https://api.github.com/repos/reactjs/react-rails/issues/143","id":70438730,"user":{"login":"xionon","id":2135,"avatar_url":"https://avatars.githubusercontent.com/u/2135?v=3","gravatar_id":"","url":"https://api.github.com/users/xionon","html_url":"https://github.com/xionon","followers_url":"https://api.github.com/users/xionon/followers","following_url":"https://api.github.com/users/xionon/following{/other_user}","gists_url":"https://api.github.com/users/xionon/gists{/gist_id}","starred_url":"https://api.github.com/users/xionon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xionon/subscriptions","organizations_url":"https://api.github.com/users/xionon/orgs","repos_url":"https://api.github.com/users/xionon/repos","events_url":"https://api.github.com/users/xionon/events{/privacy}","received_events_url":"https://api.github.com/users/xionon/received_events","type":"User","site_admin":false},"created_at":"2015-01-19T02:14:39Z","updated_at":"2015-01-19T02:14:39Z","body":"I am skeptical that anything that includes some sort of Flux library and runs arbitrary code per-request will have decent performance, given the current JS-from-Rails ecosystem. If it could be proven that response time wasn't significantly affected by this, I'd definitely change my mind.\r\n\r\nIMO, react-rails should focus on providing up-to-date versions of React for the asset pipeline, prerendering based on a given set of properties, and Rails-y helpers (methods, generators, and installers). Anything beyond that should be provided by external libraries."}}