Last active
August 29, 2015 14:10
-
-
Save vanwagonet/d707683604a3e4ad042a to your computer and use it in GitHub Desktop.
Keep controller logic out of view components using react-router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<Route handler={ require('./main-page') } dataStore={ require('./main-page-data-factory') }> | |
... | |
Router.run(routes, function(err, Handler, state) { | |
let sdata = state.dataStore.getServer(); // Hander.dataStore.getServer() | |
sdata.get().then(funciton(data) { | |
React.renderToString(<Handler data={ data }>); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://facebook.github.io/react/tips/initial-ajax.html is antagonistic to server rendering (and therefore isomorphism). I would consider it anti-pattern in Flux.
http://facebook.github.io/react/docs/interactivity-and-dynamic-uis.html recommends "Try to keep as many of your components as possible stateless." I would go a step further and say application state goes in data stores, and only UI state (isFocused, isOpen, drag location, etc) goes in components.
react-router is a controller. It's odd that routes are represented as components, especially since they they don't get rendered. @rpflorence, I think that's the crux of our difference in opinion. You want to represent your controllers as components. I think that controllers choosing the view and model are better represented in another way. The components don't know how to get data, just how to render it.