const Immutable = require('immutable'); import * as TroggleActions from '../../actions/board/troggle.actions'; const initial = []; const reducer = (state = initial, action) => { if (action.type !== TroggleActions.TROGGLE_ACTION) { return state; } switch (action.action) { case TroggleActions.UPDATE: return Immutable.fromJS(state) .setIn([action.index, 'x'], action.x) .setIn([action.index, 'y'], action.y) .toJS(); case TroggleActions.CREATE: return Immutable.List(state) .set(action.index, { x: action.x, y: action.y }) .toArray(); case TroggleActions.CLEAR_ALL: return Immutable.List() .toArray(); }; return state; }; export default reducer;