Skip to content

Instantly share code, notes, and snippets.

@meChrisReed
Created March 17, 2018 17:28
Show Gist options
  • Save meChrisReed/6e30b7b3692a99eab93337e6c3de7180 to your computer and use it in GitHub Desktop.
Save meChrisReed/6e30b7b3692a99eab93337e6c3de7180 to your computer and use it in GitHub Desktop.
for a Medium article
// 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)
// 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