Created
April 13, 2015 13:57
-
-
Save nambrot/6db6304068ddbe3ce6dc to your computer and use it in GitHub Desktop.
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
# server.coffee | |
renderToString = (route, serializedStoreState, callback) -> | |
flux = new Flux() | |
flux.deserialize(serializedStoreState) | |
Router.run routes, route, (Handler, state) -> | |
html = React.renderToString(<FluxComponent flux={flux} render={ => <Handler />}></FluxComponent>) | |
embeddedStoreState = "<script>" | |
embeddedStoreState += "window.serializedStoreState = " + JSON.stringify(serializedStoreState) | |
embeddedStoreState += "</script>" | |
callback (html + embeddedStoreState) | |
# app/helpers/react_helper.rb | |
module ReactHelper | |
def renderSerializedStoreState(state) | |
component = HTTParty.post "http://localhost:3001", body: {path: request.path, serializedStoreState: state.to_json}.to_json, headers: {'Content-Type' => "application/json"} | |
component.html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment