Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ADD = 'ADD';
- const reducer = (state = 0, action) => {
- switch(action.type) {
- case ADD:
- return state + 1;
- default:
- return state;
- }
- };
- const store = Redux.createStore(reducer);
- // global count variable:
- let count = 0;
- // change code below this line
- store.subscribe(function() { //this callback function will run every time that the store receives an action. In this case, it would also change the global variable.
- count += 1;
- })
- // change code above this line
- store.dispatch({type: ADD});
- console.log(count);
- store.dispatch({type: ADD});
- console.log(count);
- store.dispatch({type: ADD});
- console.log(count);
Add Comment
Please, Sign In to add comment