Skip to content

Instantly share code, notes, and snippets.

@vanwagonet
Last active August 29, 2015 14:10
Show Gist options
  • Save vanwagonet/d707683604a3e4ad042a to your computer and use it in GitHub Desktop.
Save vanwagonet/d707683604a3e4ad042a to your computer and use it in GitHub Desktop.
Keep controller logic out of view components using react-router
...
<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 }>);
});
});
@brentropy
Copy link

I like it.

@vanwagonet
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment