Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import { createStore } from 'redux'
  2.  
  3. function reducer(state = { count: 0 }, action) {
  4. switch (action.type) {
  5. case 'increment':
  6. return { ...state, count: state.count + 1 }
  7. default:
  8. return state
  9. }
  10. }
  11.  
  12. const store = createStore(reducer, undefined)
  13.  
  14. console.log('init', store.getState())
  15. store.dispatch({ type: 'increment' })
  16.  
  17. console.log('dispatched', store.getState())
  18.  
  19. const snapshot = store.getState()
  20. const newStore = createStore(reducer, snapshot)
  21.  
  22. console.log('take over', newStore.getState())
  23. newStore.dispatch({ type: 'increment' })
  24.  
  25. console.log('dispatched', newStore.getState())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement