From 7b51f12813ab145304c15f0d39222a2811e6ca4d Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 26 Jul 2016 02:09:54 +0800 Subject: [web] bug fix and add test --- web/src/js/ducks/utils/view.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'web/src/js/ducks/utils') 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) -- cgit v1.2.3