diff options
Diffstat (limited to 'web/src/js/ducks/utils/view.js')
-rwxr-xr-x | web/src/js/ducks/utils/view.js | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js index 87f9bd2a..2296e454 100755 --- a/web/src/js/ducks/utils/view.js +++ b/web/src/js/ducks/utils/view.js @@ -1,7 +1,7 @@ import _ from 'lodash' export const UPDATE_FILTER = 'VIEW_UPDATE_FILTER' -export const UPDATE_SORTER = 'VIEW_UPDATE_SORTER' +export const UPDATE_SORT = 'VIEW_UPDATE_SORT' export const ADD = 'VIEW_ADD' export const UPDATE = 'VIEW_UPDATE' export const REMOVE = 'VIEW_REMOVE' @@ -16,7 +16,7 @@ export default function reduce(state = defaultState, action) { switch (action.type) { case UPDATE_FILTER: { - const data = action.list.data.filter(action.filter).sort(action.sorter) + const data = action.list.data.filter(action.filter).sort(action.sort) return { ...state, data, @@ -24,8 +24,8 @@ export default function reduce(state = defaultState, action) { } } - case UPDATE_SORTER: { - const data = [...state.data].sort(action.sorter) + case UPDATE_SORT: { + const data = [...state.data].sort(action.sort) return { ...state, data, @@ -39,7 +39,7 @@ export default function reduce(state = defaultState, action) { } return { ...state, - ...sortedInsert(state, action.item, action.sorter), + ...sortedInsert(state, action.item, action.sort), } case REMOVE: @@ -64,12 +64,12 @@ export default function reduce(state = defaultState, action) { } return { ...nextState, - ...sortedInsert(nextState, action.item, action.sorter) + ...sortedInsert(nextState, action.item, action.sort) } } case RECEIVE: { - const data = action.list.data.filter(action.filter).sort(action.sorter) + const data = action.list.data.filter(action.filter).sort(action.sort) return { ...state, data, @@ -82,32 +82,32 @@ export default function reduce(state = defaultState, action) { } } -export function updateFilter(list, filter = defaultFilter, sorter = defaultSorter) { - return { type: UPDATE_FILTER, list, filter, sorter } +export function updateFilter(list, filter = defaultFilter, sort = defaultSort) { + return { type: UPDATE_FILTER, list, filter, sort } } -export function updateSorter(sorter = defaultSorter) { - return { type: UPDATE_SORTER, sorter } +export function updateSort(sort = defaultSort) { + return { type: UPDATE_SORT, sort } } -export function add(item, filter = defaultFilter, sorter = defaultSorter) { - return { type: ADD, item, filter, sorter } +export function add(item, filter = defaultFilter, sort = defaultSort) { + return { type: ADD, item, filter, sort } } -export function update(id, item, filter = defaultFilter, sorter = defaultSorter) { - return { type: UPDATE, id, item, filter, sorter } +export function update(id, item, filter = defaultFilter, sort = defaultSort) { + return { type: UPDATE, id, item, filter, sort } } export function remove(id) { return { type: REMOVE, id } } -export function receive(list, filter = defaultFilter, sorter = defaultSorter) { - return { type: RECEIVE, list, filter, sorter } +export function receive(list, filter = defaultFilter, sort = defaultSort) { + return { type: RECEIVE, list, filter, sort } } -function sortedInsert(state, item, sorter) { - const index = sortedIndex(state.data, item, sorter) +function sortedInsert(state, item, sort) { + const index = sortedIndex(state.data, item, sort) const data = [...state.data] const indexOf = { ...state.indexOf } @@ -132,13 +132,13 @@ function sortedRemove(state, id) { return { data, indexOf } } -function sortedIndex(list, item, sorter) { +function sortedIndex(list, item, sort) { let low = 0 let high = list.length while (low < high) { const middle = (low + high) >>> 1 - if (sorter(item, list[middle]) >= 0) { + if (sort(item, list[middle]) >= 0) { low = middle + 1 } else { high = middle @@ -152,6 +152,6 @@ function defaultFilter() { return true } -function defaultSorter(a, b) { +function defaultSort(a, b) { return 0 } |