Skip to content

Instantly share code, notes, and snippets.

@park-brian
Last active August 29, 2017 03:06
Show Gist options
  • Save park-brian/3648e98212051b3712c9c7252ebfb536 to your computer and use it in GitHub Desktop.
Save park-brian/3648e98212051b3712c9c7252ebfb536 to your computer and use it in GitHub Desktop.
actual redux
<!DOCTYPE html>
<html>
<body>
<span id="counter"></span>
<button id="inc">+</button>
<button id="dec">-</button>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>
<script>
const reducer = (state, action) => ({
INC: {...state, counter: state.counter + 1},
DEC: {...state, counter: state.counter - 1},
}[action.type] || state);
const store = Redux.createStore(reducer, {counter: 0})
const render =
() => document.getElementById('counter').innerText = store.getState().counter;
store.subscribe(render);
document.getElementById('inc').onclick =
() => store.dispatch({type: 'INC'})
document.getElementById('dec').onclick =
() => store.dispatch({type: 'DEC'})
render();
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment