Last active
January 25, 2016 13:31
-
-
Save tomkis/938cf7c67103c659ecaf to your computer and use it in GitHub Desktop.
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
// 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