[web] flows.makeFun

This commit is contained in:
Jason 2016-06-23 01:01:39 +08:00
parent 60ea300990
commit 2a9a6f6151

View File

@ -24,7 +24,7 @@ export default function reduce(state = defaultState, action) {
return { return {
...state, ...state,
filter: action.filter, filter: action.filter,
list: reduceList(state.list, listActions.updateFilter(action.filter ? Filt.parse(action.filter) : () => true)), list: reduceList(state.list, listActions.updateFilter(makeFilterFun(action.filter))),
} }
case UPDATE_HIGHLIGHT: case UPDATE_HIGHLIGHT:
@ -34,21 +34,10 @@ export default function reduce(state = defaultState, action) {
} }
case UPDATE_SORTER: case UPDATE_SORTER:
const { column, desc, sortKeyFun } = action
return { return {
...state, ...state,
sorter: { column, desc }, sorter: { column: action.column, desc: action.desc },
list: reduceList(state.list, listActions.updateSorter((a, b) => { list: reduceList(state.list, listActions.updateSorter(makeSortFun(action.sortKeyFun, action.desc))),
const ka = sortKeyFun(a)
const kb = sortKeyFun(b)
if (ka > kb) {
return desc ? -1 : 1
}
if (ka < kb) {
return desc ? 1 : -1
}
return 0
})),
} }
case SELECT: case SELECT:
@ -68,6 +57,24 @@ export default function reduce(state = defaultState, action) {
} }
} }
function makeFilterFun(filter) {
return filter ? Filt.parse(filter) : () => true
}
function makeSortFun(sortKeyFun, desc) {
return (a, b) => {
const ka = sortKeyFun(a)
const kb = sortKeyFun(b)
if (ka > kb) {
return desc ? -1 : 1
}
if (ka < kb) {
return desc ? 1 : -1
}
return 0
}
}
/** /**
* @public * @public
*/ */