Skip to content

Instantly share code, notes, and snippets.

@hadijaveed
Last active May 28, 2017 22:45
Show Gist options
  • Save hadijaveed/0876154665fc1a1561a772bab9e23f10 to your computer and use it in GitHub Desktop.
Save hadijaveed/0876154665fc1a1561a772bab9e23f10 to your computer and use it in GitHub Desktop.
Counter Example With Redux
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