diff options
author | Jason <jason.daurus@gmail.com> | 2016-06-27 18:36:21 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-06-27 18:42:20 +0800 |
commit | 37c2b47c26dea9b143b2720761cdce21dafd3884 (patch) | |
tree | 5ec4f45e38e69b3af96ecc4372d70cda5bbe0c83 /web/src/js/ducks/utils/list.js | |
parent | 28531a4dd7acd6dfd32dafca99dcad286041003b (diff) | |
download | mitmproxy-37c2b47c26dea9b143b2720761cdce21dafd3884.tar.gz mitmproxy-37c2b47c26dea9b143b2720761cdce21dafd3884.tar.bz2 mitmproxy-37c2b47c26dea9b143b2720761cdce21dafd3884.zip |
[web] add tests for utils
Diffstat (limited to 'web/src/js/ducks/utils/list.js')
-rw-r--r-- | web/src/js/ducks/utils/list.js | 18 |
1 files changed, 9 insertions, 9 deletions
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 |