Skip to content

Commit

Permalink
Update example to use state-reuse init
Browse files Browse the repository at this point in the history
  • Loading branch information
glenjamin committed May 31, 2015
1 parent 8ee6e69 commit 4535495
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions examples/react-iso/client/dispatcher.js
Original file line number Diff line number Diff line change
@@ -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!
*
Expand All @@ -8,22 +17,14 @@ 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;
}
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');

Expand Down

0 comments on commit 4535495

Please sign in to comment.