Created
March 17, 2018 17:28
-
-
Save meChrisReed/6e30b7b3692a99eab93337e6c3de7180 to your computer and use it in GitHub Desktop.
for a Medium article
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
// To connect to a component | |
const enhance = connect(["things", "things.reset"]) | |
const CoolComponent = ({ things }) => ( | |
<Fragment> | |
<button onClick={things.reset}> Reset </button> | |
{things.i.map(i => <span>{i}</span>)} | |
</Fragment> | |
) | |
enhance(CoolComponent) |
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
// To create a root reducer | |
import { combineCreators, createReducer as r } from "ultra-instinct-connect" | |
combineCreators({ | |
things: r([], { | |
replace: (_, { things }) => things, | |
accumulate: (state, { things }) => [...state, ...things], | |
remove: (state, { id }) => state.filter(i => i.id !== id), | |
reset: () => [] | |
}), | |
uiThing: r(false, { | |
"things.reset": () => false, | |
on: () => true, | |
off: () => false | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment