diff options
author | Jason <jason.daurus@gmail.com> | 2016-07-26 02:09:54 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-07-26 02:09:54 +0800 |
commit | 7b51f12813ab145304c15f0d39222a2811e6ca4d (patch) | |
tree | 6f0dbbe7f6e75fb9accad70278cc6d7b283681f6 /web/src/js/ducks/utils/view.js | |
parent | 3a3305b9acbb3ac3ac82f9b29c099699b5210fa5 (diff) | |
download | mitmproxy-7b51f12813ab145304c15f0d39222a2811e6ca4d.tar.gz mitmproxy-7b51f12813ab145304c15f0d39222a2811e6ca4d.tar.bz2 mitmproxy-7b51f12813ab145304c15f0d39222a2811e6ca4d.zip |
[web] bug fix and add test
Diffstat (limited to 'web/src/js/ducks/utils/view.js')
-rwxr-xr-x | web/src/js/ducks/utils/view.js | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js index 2f1e03fa..fdddc391 100755 --- a/web/src/js/ducks/utils/view.js +++ b/web/src/js/ducks/utils/view.js @@ -54,14 +54,30 @@ export default function reduce(state = defaultState, action) { } case UPDATE: - if (state.indexOf[action.item.id] == null) { - return + let hasOldItem = state.indexOf[action.item.id] !== null && state.indexOf[action.item.id] !== undefined + let hasNewItem = action.filter(action.item) + if (!hasNewItem && !hasOldItem) { + return state } - return { - ...state, - ...sortedUpdate(state, action.item, action.sort), + if (hasNewItem && !hasOldItem) { + return { + ...state, + ...sortedInsert(state, action.item, action.sort) + } } - + if (!hasNewItem && hasOldItem) { + return { + ...state, + ...sortedRemove(state, action.item.id) + } + } + if (hasNewItem && hasOldItem) { + return { + ...state, + ...sortedUpdate(state, action.item, action.sort), + } + } + break; case RECEIVE: { const data = action.list.filter(action.filter).sort(action.sort) |