Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {createStore} = require("redux");
- const initialState = { age:21 };
- const myReducer = (state = initialState, action) =>
- {
- if(action.type === 'ADD'){ state.age += 1; }
- // console.log('Hello' );
- // console.log(JSON.stringify(state) );
- // console.log(state.age);
- return state;
- }
- const store = createStore(myReducer);
- store.dispatch({type: 'ADD'});
- store.subscribe(()=>{
- console.log('Hello' );
- console.log(JSON.stringify(store) );
- console.log(store.age);
- });
- store.dispatch({type: 'ADD'});
- node redrec.js
- Hello
- {}
- undefined
- Hello
- {"age":21}
- 21
- Hello
- {"age":22}
- 22
- Hello
- {"age":23}
- 23
- Hello
- {}
- undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement