web: accept all falsey sortFns in sortedIndexOf

This commit is contained in:
Maximilian Hils 2016-06-06 15:47:31 -07:00
parent 7cb7d9ad32
commit 54ee8ff4d4

View File

@ -43,12 +43,8 @@ const sortedRemove = (list, sortFn, item) => {
} }
export function sortedIndexOf(list, value, sortFn) { export function sortedIndexOf(list, value, sortFn) {
if (sortFn === false){ if (!sortFn) {
let i = 0 sortFn = x => 0 // This triggers the linear search for flows that have the same sort value.
while (i < list.length && list[i].id !== value.id){
i++
}
return i
} }
let low = 0, let low = 0,
@ -57,7 +53,7 @@ export function sortedIndexOf(list, value, sortFn) {
mid; mid;
while (low < high) { while (low < high) {
mid = (low + high) >>> 1; mid = (low + high) >>> 1;
if ((sortFn(list[mid]) < val) ) { if (sortFn(list[mid]) < val) {
low = mid + 1 low = mid + 1
} else { } else {
high = mid high = mid
@ -125,4 +121,4 @@ export function updateViewFilter(list, filterFn = defaultFilterFn, sortFn = defa
filtered.indexOf = x => sortedIndexOf(filtered, x, sortFn) filtered.indexOf = x => sortedIndexOf(filtered, x, sortFn)
return filtered return filtered
} }