Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. const {createStore} = require("redux");
  2. const initialState = { age:21 };
  3. const myReducer = (state = initialState, action) =>
  4. {
  5. if(action.type === 'ADD'){ state.age += 1; }
  6.  
  7. // console.log('Hello' );
  8. // console.log(JSON.stringify(state) );
  9. // console.log(state.age);
  10.  
  11. return state;
  12. }
  13. const store = createStore(myReducer);
  14. store.dispatch({type: 'ADD'});
  15. store.subscribe(()=>{
  16.  
  17. console.log('Hello' );
  18. console.log(JSON.stringify(store) );
  19. console.log(store.age);
  20.  
  21. });
  22. store.dispatch({type: 'ADD'});
  23.  
  24. node redrec.js
  25.  
  26. Hello
  27. {}
  28. undefined
  29.  
  30. Hello
  31. {"age":21}
  32. 21
  33. Hello
  34. {"age":22}
  35. 22
  36. Hello
  37. {"age":23}
  38. 23
  39. Hello
  40. {}
  41. undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement