var initialState = {counter: 0}
var store = Redux.createStore(reducer, initialState)
function render(state) {
document.getElementById('counter').textContent = state.counter;
}
document.getElementById('button').addEventListener('click', function() {
incrementCounter()
})
function incrementCounter() {
store.dispatch({
type: 'INCREMENT'
})
}
function reducer(state, action) {
if (action.type === 'INCREMENT') {
state = Object.assign({}, state, {counter: state.counter + 1})
}
return state
}
store.subscribe(function() {
render(store.getState())
})
// Render the initial state
render(store.getState())
<div id="counter">-</div>
<button id="button">Inc</button>
External resources loaded into this fiddle: