Question about the collection of storage data in applications with an isomorphic stream. (I use reaction, alt, iso and node, but the theory applies to other examples)
I have a flux drive ( http://alt.js.org/docs/stores/ ) that should receive data from api:
getState() { return { data : makeHttpRequest(url) } }
and when the user goes through the SPA, more data will be downloaded via HTTP requests.
I want this application to be isomorphic so that I can display applications with full html, including the last part of the data server, and return it to the user for quick loading of the start page.
response.renderToString () allows me to display the application as html, and I can sow data using alt & iso like:
storeData = { "MyStore" : {"key" : "value"}}; // set data for store alt.bootstrap(JSON.stringify(storeData || {})); // seed store with data var content = React.renderToString(React.createElement(myApp)); // render react app to html
The problem is that I will see errors when starting the js server, since the repository wants to make an HTTP request that it cannot fulfill (since xmlhttprequest does not exist in node)
What is the best way to solve this problem?
The only solution I can think of is to wrap the httprequest from the store using
var ExecutionEnvironment = require('react/lib/ExecutionEnvironment'); ... if (ExecutionEnvironment.canUseDOM) { // make http request } else { // do nothing }
Any better ideas? Thanks in advance.