Skip to content

Instantly share code, notes, and snippets.

@tomkis
Last active January 25, 2016 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomkis/938cf7c67103c659ecaf to your computer and use it in GitHub Desktop.
Save tomkis/938cf7c67103c659ecaf to your computer and use it in GitHub Desktop.
// Current Redux way
const view = props => (
<div>
<button onClick={props.dispatch({type: 'FOO'})}>FooBar</button>
<button onClick={props.dispatch({type: 'BAR'})}>FooBar</button>
<button onClick={props.dispatch({type: 'BAZ'})}>Baz</button>
</div>
);
const store = createStore(rootReducer);
const rootReducer = (appState, action) => {
switch (action.type) {
case 'FOO':
case 'BAR':
return doFooOrBar(appState, action.payload);
case 'BAZ:
return compose(doQux, doBaz)(appState);
default:
return appState;
}
};
// Proposal: if we could simply address updater instead of dispatching action
// not saying it's currently possible in redux.
const view = props => (
<div>
<button onClick={props.address(doFooOrBar)}>FooBar</button>
<button onClick={props.address(doFooOrBar)}>FooBar</button>
<button onClick={props.address(doBaz)}>Baz</button>
</div>
);
const doFooOrBar => appState => ....
const doBaz => appState => compose(doQux, doBaz)(appState);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment