Created
October 17, 2018 16:32
-
-
Save jepras/b3eceb4bca51a99d8563304020126134 to your computer and use it in GitHub Desktop.
Used store.subscribe to invoke a callback function that simply adds +1 to count. Store.subscribe fires automatically when an action is dispatched.
This file contains 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
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( () => { ++count } ) | |
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment