Last active
May 28, 2017 22:45
-
-
Save hadijaveed/0876154665fc1a1561a772bab9e23f10 to your computer and use it in GitHub Desktop.
Counter Example With Redux
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
let reducer = function(state = 0, action) { | |
switch(action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECEMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
}; | |
const store = Redux.createStore(reducer); | |
let render = count => document.getElementById('count').innerHTML = count; | |
store.subscribe(() => { | |
render(store.getState()); | |
}); | |
store.dispatch({ type: '' }); | |
document.getElementById('increment') | |
.addEventListener('click', () => { | |
store.dispatch({ type: 'INCREMENT' }); | |
}); | |
document.getElementById('decerement') | |
.addEventListener('click', () => { | |
store.dispatch({ type: 'DECEMENT' }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment