Skip to content

Instantly share code, notes, and snippets.

@iktash
Created October 22, 2018 06:50
Show Gist options
  • Save iktash/3f6ab69744df9cc0b78f81d3a84b354a to your computer and use it in GitHub Desktop.
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
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