diff --git a/examples/react-iso/client/dispatcher.js b/examples/react-iso/client/dispatcher.js index 506892d..4a93cd4 100644 --- a/examples/react-iso/client/dispatcher.js +++ b/examples/react-iso/client/dispatcher.js @@ -1,5 +1,14 @@ var flux = require('flux-redux'); +/** + * To take over from server rendering, we must re-use the data that the + * server used, by passing it into the dispatcher init + */ +/*global initialStoreData*/ +var state = typeof initialStoreData == 'object' ? initialStoreData : {}; + +var dispatcher = flux.createDispatcher({state}); + /** * Hot reloading stores! * @@ -8,7 +17,6 @@ var flux = require('flux-redux'); * dispatcher.addStore will use the stores' merge functions * when re-adding another store with the same key */ -var dispatcher = flux.createDispatcher(); if (module.hot) { if (module.hot.data) { dispatcher = module.hot.data.dispatcher; @@ -16,14 +24,7 @@ if (module.hot) { module.hot.accept(); module.hot.dispose(hot => hot.dispatcher = dispatcher); } -// Server data hydration - this should be in the core lib -/*global initialStoreData*/ -if (typeof initialStoreData == 'object') { - Object.keys(initialStoreData).forEach(k => { - dispatcher.addStore(k, {initial: () => initialStoreData[k]}); - delete initialStoreData[k]; - }); -} + var data = require('./data');