From 37c2b47c26dea9b143b2720761cdce21dafd3884 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 27 Jun 2016 18:36:21 +0800 Subject: [web] add tests for utils --- web/src/js/ducks/utils/list.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'web/src/js/ducks/utils/list.js') diff --git a/web/src/js/ducks/utils/list.js b/web/src/js/ducks/utils/list.js index 71042d91..4f631590 100644 --- a/web/src/js/ducks/utils/list.js +++ b/web/src/js/ducks/utils/list.js @@ -23,33 +23,33 @@ export default function reduce(state = defaultState, action) { } case UPDATE: { - const data = [...state.data] const index = state.indexOf[action.id] - // FIXME: We should just swallow this if (index == null) { - throw new Error('Item not found') + return state } + const data = [...state.data] + data[index] = action.item return { ...state, data, - byId: { ...state.byId, [action.item.id]: action.item }, + byId: { ...state.byId, [action.id]: action.item } } } case REMOVE: { - const data = [...state.data] - const indexOf = { ...state.indexOf } - const index = indexOf[action.id] + const index = state.indexOf[action.id] - // FIXME: We should just swallow this if (index == null) { - throw new Error('Item not found') + return state } + const data = [...state.data] + const indexOf = { ...state.indexOf, [action.id]: null } + data.splice(index, 1) for (let i = data.length - 1; i >= index; i--) { indexOf[data[i].id] = i -- cgit v1.2.3