Created
August 11, 2016 12:11
-
-
Save joshwcomeau/b8c5bb5945cb37d3f904cd01f8bcca87 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
const initialState = { | |
casettes: {}, | |
selectedCasette: null, | |
casetteStatus: 'idle', // One of 'idle', 'selecting', 'loaded' | |
casettePageNumber: 0, | |
casettePageLimit: 3, | |
}; | |
export default function reducer(state = initialState, action) { | |
switch (action.type) { | |
case CASETTES_LIST_RECEIVE: { | |
return { | |
...state, | |
casettes: action.casettes, | |
}; | |
} | |
case VIEW_CASETTES: { | |
return { | |
...state, | |
casetteStatus: 'selecting', | |
}; | |
} | |
case HIDE_CASETTES: { | |
return { | |
...state, | |
casetteStatus: 'idle', | |
}; | |
} | |
case SELECT_CASETTE: { | |
return { | |
...state, | |
casetteStatus: 'loaded', | |
selectedCasette: action.id, | |
}; | |
} | |
case EJECT_CASETTE: { | |
return { | |
...state, | |
casetteStatus: 'idle', | |
}; | |
} | |
case GO_TO_NEXT_CASETTE_PAGE: { | |
return { | |
...state, | |
casettePageNumber: state.casettePageNumber + 1, | |
}; | |
} | |
case GO_TO_PREVIOUS_CASETTE_PAGE: { | |
return { | |
...state, | |
casettePageNumber: state.casettePageNumber - 1, | |
}; | |
} | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment