Last active
August 11, 2016 12:16
-
-
Save joshwcomeau/0b4f32b998050581b2e0ebc0dd474546 to your computer and use it in GitHub Desktop.
Disappointing Ducks
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
function statusReducer(state = 'idle', action) { | |
switch (action.type) { | |
case VIEW_CASETTES: | |
return 'selecting'; | |
case EJECT_CASETTE: | |
case HIDE_CASETTES: | |
return 'idle'; | |
case SELECT_CASETTE: | |
return 'loaded'; | |
default: | |
return state; | |
} | |
} | |
function selectedReducer(state = null, action) { | |
switch (action.type) { | |
case SELECT_CASETTE: return action.id; | |
default: return state; | |
} | |
} | |
function byIdReducer(state = {}, action) { | |
switch (action.type) { | |
case CASETTES_LIST_RECEIVE: return action.casettes; | |
default: return state; | |
} | |
} | |
function pageNumberReducer(state = 0, action) { | |
switch (action.type) { | |
case GO_TO_NEXT_CASETTE_PAGE: return state + 1; | |
case GO_TO_PREVIOUS_CASETTE_PAGE: return state - 1; | |
default: return state; | |
} | |
} | |
function pageLimitReducer(state = 3, action) { | |
switch (action.type) { | |
default: return state; | |
} | |
} | |
export default combineReducers({ | |
status: casetteStatusReducer, | |
selected: selectedReducer, | |
byId: byIdReducer, | |
page: combineReducers({ | |
number: pageNumberReducer, | |
limit: pageLimitReducer, | |
}), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment