Last active
August 29, 2017 03:06
-
-
Save park-brian/3648e98212051b3712c9c7252ebfb536 to your computer and use it in GitHub Desktop.
actual 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
<!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