Last active
March 19, 2016 05:29
-
-
Save rt2zz/6f737b96e4dfdd11f1b8 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
import stringify from 'json-stringify-safe' | |
// use a special rehydrating reducer | |
const rehydratingReducer = (state, action) => { | |
if (action.type === 'REHYDRATE') return action.payload | |
else return reducer(state, action) | |
} | |
// subscribe to store and serialize safely | |
// should either debounce or selectively run this method as it is expensive | |
store.subscribe(() => { | |
console.log(stringify(store.getState())) | |
}) | |
// sometime later dispatch a rehydrate action with the entire state to replace | |
store.dispatch({type: 'REHYDRATE', payload: JSON.parse(oneState)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment