Skip to content

Instantly share code, notes, and snippets.

@rt2zz
Created July 31, 2015 01:32
Show Gist options
  • Save rt2zz/44da33c6b4a1f4fa46a2 to your computer and use it in GitHub Desktop.
Save rt2zz/44da33c6b4a1f4fa46a2 to your computer and use it in GitHub Desktop.
var actions = {
increment(){
return {
type: INCREMENT
}
}
}
function dispatchFn(dispatch){
return bindActionCreators(actions, dispatch)
}
var ControlPanelNode = createActionNode(dispatchFn)
var ControlPanelConnector = createActionNode(dispatchFn)(createConnector(stateFn, null, merge)(ControlPanelNode))
<Provider>
<ControlPanelConnector />
</Provider>
@attachActions((nodeActions) => {
return {
increment: nodeActions.increment
}
})
class ControlPanel extends Component {
// this.props.actions.increment()
}

Thoughts

  • Nice to colocate actions and connector

  • Nice to explicitly seperate actions and state (CQRS?)

  • Nice to wormhole actions into deeply nested things like buttons

  • Kind of emulates the "global shared state" concept, except with multiple nodes which better reflects how actions are conceived

  • State renders down (hence pass down as props)

  • Actions flow back to the root (hence wormhole at extremities)

  • Can throw if requested action does not exist in actionNode

  • Can theoretically nest actionNodes, but only the closest node will be selectable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment