Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Created August 11, 2016 12:11
Show Gist options
  • Save joshwcomeau/b8c5bb5945cb37d3f904cd01f8bcca87 to your computer and use it in GitHub Desktop.
Save joshwcomeau/b8c5bb5945cb37d3f904cd01f8bcca87 to your computer and use it in GitHub Desktop.
Disappointing Ducks
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