Created
October 22, 2018 06:50
-
-
Save iktash/3f6ab69744df9cc0b78f81d3a84b354a to your computer and use it in GitHub Desktop.
A tiny example of an application state management done in a fully functional manner
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
const getDispatch = (initialState, render) => { | |
let stateContainer = Container.of(initialState); | |
const updateState = action => new IO(() => { | |
stateContainer = stateContainer.map(action); | |
return stateContainer; | |
}); | |
return action => { | |
const sideEffects = pipe( | |
updateState, | |
chain(containerToIO), | |
chain(render) | |
)(action); | |
sideEffects.performUnsafeIO(); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment