Created
April 3, 2016 19:10
-
-
Save arnarthor/b7d14ed16c1b431c619d48b7927c4208 to your computer and use it in GitHub Desktop.
This file contains 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
// 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') | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So do you still have some declarative (promised-based) resolver? Or is everything just thrown in
componentDidMount
at that point?