Created
October 2, 2016 21:53
-
-
Save vojtatranta/e4058b6a5b2cafea811155a2403b6844 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const createDispatch = (state, doThingsWithUpdatedState) => { | |
return (executeChange) => { | |
const newState = executeChange(state) | |
return doThingsWithUpdatedState(newState, createDispatch(newState, doThingsWithUpdatedState)) | |
} | |
} | |
const initialState = { counter: 0 } | |
const dispatch = createDispatch(initialState, (newState, dispatch) => { | |
document.write(newState.counter) | |
setTimeout(() => { | |
dispatch(({ counter }) => ({ counter: ++counter })) | |
}, 1000) | |
}) | |
// start it! | |
dispatch(state => state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment