Skip to content

Instantly share code, notes, and snippets.

@arnarthor
Created April 3, 2016 19:10
Show Gist options
  • Save arnarthor/b7d14ed16c1b431c619d48b7927c4208 to your computer and use it in GitHub Desktop.
Save arnarthor/b7d14ed16c1b431c619d48b7927c4208 to your computer and use it in GitHub Desktop.
// server.js
function sendHtml(req, res) {
const data = {
request: {
id: req.id,
},
me: req.player
};
const payload = encodeTextContent(
transitImmutable.toJSON(data)
);
const output = templates[req.bundle]({
payload,
});
res.send(output);
}
// template.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="icon" href="<%= htmlWebpackPlugin.options.title %>" sizes="32x32" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="root"></div>
<script id="payload" type="application/payload">{{{payload}}}</script>
</body>
</html>
// index.js Root react component
const payload = transitImmutable.fromJSON(
decodeTextContent(document.getElementById('payload').textContent)
);
const store = configureStore(payload);
syncReduxAndRouter(browserHistory, store);
if (typeof document !== 'undefined') {
render(
<Provider store={store}>
<span>
{getRoutes(store, browserHistory)}
</span>
</Provider>,
document.getElementById('root')
);
}
@jaredpalmer
Copy link

"We do the route matching to fetch all route specific data."

So do you still have some declarative (promised-based) resolver? Or is everything just thrown in componentDidMount at that point?

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