diff options
Diffstat (limited to 'web/src/js/ducks')
| -rw-r--r-- | web/src/js/ducks/utils/list.js | 9 | ||||
| -rw-r--r-- | web/src/js/ducks/utils/view.js | 18 |
2 files changed, 13 insertions, 14 deletions
diff --git a/web/src/js/ducks/utils/list.js b/web/src/js/ducks/utils/list.js index a5ce7250..a830fe99 100644 --- a/web/src/js/ducks/utils/list.js +++ b/web/src/js/ducks/utils/list.js @@ -62,8 +62,9 @@ export default function makeList(actionType, fetchURL) { itemIndex = state.indexOf[action.item.id] list[itemIndex] = action.item return { - ...defaultState, - list + ...state, + list, + byId: {...state.byId, [action.item.id]: action.item}, } case REMOVE: @@ -71,7 +72,7 @@ export default function makeList(actionType, fetchURL) { itemIndex = state.indexOf[action.item.id] list.splice(itemIndex, 1) return { - ...defaultState, + ...state, list, byId: {...state.byId, [action.item.id]: undefined}, indexOf: {...state.indexOf, [action.item.id]: undefined}, @@ -79,7 +80,7 @@ export default function makeList(actionType, fetchURL) { case REQUEST_LIST: return { - ...defaultState, + ...state, isFetching: true } diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js index 5535ed83..fa23efcd 100644 --- a/web/src/js/ducks/utils/view.js +++ b/web/src/js/ducks/utils/view.js @@ -43,12 +43,8 @@ const sortedRemove = (list, sortFn, item) => { } export function sortedIndexOf(list, value, sortFn) { - if (sortFn === false){ - let i = 0 - while (i < list.length && list[i].id !== value.id){ - i++ - } - return i + if (!sortFn) { + sortFn = x => 0 // This triggers the linear search for flows that have the same sort value. } let low = 0, @@ -57,7 +53,7 @@ export function sortedIndexOf(list, value, sortFn) { mid; while (low < high) { mid = (low + high) >>> 1; - if ((sortFn(list[mid]) < val) ) { + if (sortFn(list[mid]) < val) { low = mid + 1 } else { high = mid @@ -96,10 +92,12 @@ export function updateViewList(currentView, currentList, nextList, action, filte return sortedInsert(currentView, sortFn, action.item) if (isInView && !shouldBeInView) return sortedRemove(currentView, sortFn, action.item) - if (isInView && shouldBeInView && sortFn && sortFn(currentItemState) !== sortFn(nextItemState)) { + if (isInView && shouldBeInView) { let s = [...currentView] - s.sort(makeCompareFn(sortFn)) s.indexOf = x => sortedIndexOf(s, x, sortFn) + s[s.indexOf(currentItemState)] = nextItemState + if (sortFn && sortFn(currentItemState) !== sortFn(nextItemState)) + s.sort(makeCompareFn(sortFn)) return s } return currentView @@ -123,4 +121,4 @@ export function updateViewFilter(list, filterFn = defaultFilterFn, sortFn = defa filtered.indexOf = x => sortedIndexOf(filtered, x, sortFn) return filtered -}
\ No newline at end of file +} |
