Skip to content

Instantly share code, notes, and snippets.

@ldmarz
Created August 31, 2018 19:04
Show Gist options
  • Select an option

  • Save ldmarz/d2fbed048f82833cc718f1aa6e5136cb to your computer and use it in GitHub Desktop.

Select an option

Save ldmarz/d2fbed048f82833cc718f1aa6e5136cb to your computer and use it in GitHub Desktop.
import { GODOWN, GOUP, ELEMENTS } from '../actions.type';
const initialState = {
currentActive: 0,
elements: []
}
function listReducer(state = initialState, action) {
switch (action.type) {
case GODOWN:
state.currentActive--
state.currentActive = Math.max(state.currentActive, 0);
return state;
case GOUP:
state.currentActive++
state.currentActive = Math.min(state.currentActive, state.elements.length);
return state;
case ELEMENTS:
state.elements = action.elements;
return state;
default:
return state;
}
}
export default {listReducer};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment