diff options
author | Jason <jason.daurus@gmail.com> | 2016-07-24 18:22:40 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-07-24 18:25:09 +0800 |
commit | 3a3305b9acbb3ac3ac82f9b29c099699b5210fa5 (patch) | |
tree | 050ed30964d28b5338d8f57c8227f6aac33f44f5 /web | |
parent | a3fa9e14aea6e586e839630c57df24aea8c55d26 (diff) | |
download | mitmproxy-3a3305b9acbb3ac3ac82f9b29c099699b5210fa5.tar.gz mitmproxy-3a3305b9acbb3ac3ac82f9b29c099699b5210fa5.tar.bz2 mitmproxy-3a3305b9acbb3ac3ac82f9b29c099699b5210fa5.zip |
[web] fix: Flow update changes list order #36
Diffstat (limited to 'web')
-rwxr-xr-x | web/src/js/ducks/utils/view.js | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js index c00f00bd..2f1e03fa 100755 --- a/web/src/js/ducks/utils/view.js +++ b/web/src/js/ducks/utils/view.js @@ -57,16 +57,9 @@ export default function reduce(state = defaultState, action) { if (state.indexOf[action.item.id] == null) { return } - const nextState = { - ...state, - ...sortedRemove(state, action.item.id), - } - if (!action.filter(action.item)) { - return nextState - } return { - ...nextState, - ...sortedInsert(nextState, action.item, action.sort) + ...state, + ...sortedUpdate(state, action.item, action.sort), } case RECEIVE: @@ -110,7 +103,7 @@ export function receive(list, filter = defaultFilter, sort = defaultSort) { function sortedInsert(state, item, sort) { const index = sortedIndex(state.data, item, sort) - const data = [...state.data] + const data = [ ...state.data ] const indexOf = { ...state.indexOf } data.splice(index, 0, item) @@ -134,6 +127,28 @@ function sortedRemove(state, id) { return { data, indexOf } } +function sortedUpdate(state, item, sort) { + let data = [ ...state.data ] + let indexOf = { ...state.indexOf } + let index = indexOf[item.id] + data[index] = item + while (index + 1 < data.length && sort(data[index], data[index + 1]) > 0) { + data[index] = data[index + 1] + data[index + 1] = item + indexOf[item.id] = index + 1 + indexOf[data[index].id] = index + ++index + } + while (index > 0 && sort(data[index], data[index - 1]) < 0) { + data[index] = data[index - 1] + data[index - 1] = item + indexOf[item.id] = index - 1 + indexOf[data[index].id] = index + --index + } + return { data, indexOf } +} + function sortedIndex(list, item, sort) { let low = 0 let high = list.length |