Created
February 25, 2017 15:15
-
-
Save oliverturner/c4dc5dfcefce0e251585ed8fafc15136 to your computer and use it in GitHub Desktop.
switchless reducers
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
import addHandler from './helper' | |
import {UPDATE_PENDING, UPDATE_LOADED, UPDATE_FAILED} from './actions'; | |
const initialState = {}; | |
// Handlers | |
const onUpdatePending = (state) => state | |
const onUpdateLoaded = (state, json) => Object.assign({}, state, json); | |
const onUpdateFailed = (state, err) => state; | |
// Store | |
export default addHandlers(initialState, { | |
[UPDATE_PENDING]: onUpdatePending, | |
[UPDATE_LOADED]: onUpdateLoaded, | |
[UPDATE_FAILED]: onUpdateFailed | |
}); |
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
export default (initialState, handlers) => | |
(state = initialState, action) => | |
handlers[action.type] | |
? handlers[action.type](state, action.payload) | |
: state; |
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
import { combineReducers } from 'redux'; | |
import example from './example'; | |
export default combineReducers({example}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment