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