Redux counter
Example from https://egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe
by gaboom
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.5/redux.min.js"></script>
JavaScript
function counter (state, action) {
if (typeof state == 'undefined') {
state = 0;
}
switch (action.type) {
case 'INCREMENT':
state++;
break;
case 'DECREMENT':
state--;
break;
}
return state;
}
function render() {
document.querySelector('body').innerHTML = store.getState();
}
var store = Redux.createStore(counter);
store.subscribe(render);
render();
setInterval(function() {
store.dispatch({type: 'DECREMENT'});
}, 1000);
document.addEventListener('click', function() {
store.dispatch({type: 'INCREMENT'});
});