Last active
June 18, 2016 07:05
-
-
Save davidgilbertson/5330d167fa73c5580d64c4c1c0585086 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 {createStore} from 'redux'; | |
import reducers from './reducers'; | |
const localState = JSON.parse(localStorage.getItem('malla-store')); | |
const store = createStore(reducers, localState); | |
// Let's write the store to local storage every time it changes | |
let timer; | |
store.subscribe(() => { | |
clearTimeout(timer); | |
timer = setTimeout(() => { | |
localStorage.setItem('malla-store', JSON.stringify(store.getState())); | |
}, 500); | |
}); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment