UNPKG

my-test123

Version:
70 lines 2.71 kB
import * as WorkItemActions from './../actions/work-item.actions'; import { initialState } from './../states/work-item.state'; export var WorkItemReducer = function (state, action) { if (state === void 0) { state = initialState; } switch (action.type) { case WorkItemActions.ADD_SUCCESS: { if (action.payload.parentID) { var parentIndex = state.findIndex(function (s) { return s.id === action.payload.parentID; }); if (parentIndex > -1) { state[parentIndex].hasChildren = true; state[parentIndex].childrenLoaded = true; state[parentIndex].treeStatus = 'expanded'; } } return [action.payload].concat(state); } case WorkItemActions.ADD_ERROR: { return state; } case WorkItemActions.GET_SUCCESS: { return action.payload; } case WorkItemActions.GET_ERROR: { return state; } case WorkItemActions.GET_CHILDREN_ERROR: { var parent_1 = action.payload; var parentIndex = state.findIndex(function (s) { return s.id === action.payload.id; }); state[parentIndex].treeStatus = 'collapsed'; return state.slice(); } case WorkItemActions.GET_CHILDREN_SUCCESS: { var parent_2 = action.payload.parent; var children = action.payload.children; var parentIndex = state.findIndex(function (s) { return s.id === parent_2.id; }); if (parentIndex > -1) { state[parentIndex].childrenLoaded = true; state[parentIndex].treeStatus = 'expanded'; return state.concat(children); } return state.slice(); } case WorkItemActions.UPDATE_SUCCESS: { var index = state.findIndex(function (i) { return i.id === action.payload.id; }); if (index > -1) { return state.slice(0, index).concat([ action.payload ], state.slice(index + 1)); } return state.slice(); } case WorkItemActions.UPDATE_ERROR: { return state; } case WorkItemActions.UPDATE_WORKITEM_ITERATION: { state.forEach(function (i) { if (i.iteration.id === action.payload.iteration.id) { i.iteration = action.payload.iteration; } }); return state.slice(); } default: { return state; } } }; //# sourceMappingURL=work-item.reducer.js.map