const addAction = {
type: 'ADD',
};
const removeAction = {
type: 'REMOVE',
};
const addAction10 = {
type: 'ADD10',
};
const removeAction10 = {
type: 'REMOVE10',
};
const resetAction = {
type: 'RESET',
};
const counterReducer = (state = 0, action) => {
switch (action.type) {
case 'ADD':
return state + 1;
case 'REMOVE':
return state - 1;
case 'ADD10':
return state + 10;
case 'REMOVE10':
return state - 10;
case 'RESET' :
return state = 0;
default:
return state;
}
}
const { createStore } = Redux;
const store = createStore(counterReducer);
// MAIN
const renderStore = document.getElementById('render-store');
const render = () => {
renderStore.innerHTML = store.getState();
}
store.subscribe(render);
render();
const remove10 = document.getElementById('remove10');
remove10.addEventListener('click', () => {
store.dispatch(removeAction10)
});
const add = document.getElementById('add');
add.addEventListener('click', () => {
store.dispatch(addAction)
});