Refactor API of asyncSearch
This commit is contained in:
parent
adda5836af
commit
cc99284052
|
@ -125,8 +125,9 @@ findRootPath
|
||||||
|
|
||||||
searchHandler = searchAsync(searchText, doc, {
|
searchHandler = searchAsync(searchText, doc, {
|
||||||
onProgress: handleSearchProgressDebounced,
|
onProgress: handleSearchProgressDebounced,
|
||||||
onDone: handleSearchDone
|
onDone: handleSearchDone,
|
||||||
}, 10000, MAX_SEARCH_RESULTS)
|
maxResults: MAX_SEARCH_RESULTS
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const history = createHistory({
|
const history = createHistory({
|
||||||
|
|
|
@ -109,7 +109,7 @@ async function tick () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: comment
|
// TODO: comment
|
||||||
export function searchAsync (searchText, doc, { onProgress, onDone }, yieldAfterItemCount = 10_000, maxResults = Infinity) {
|
export function searchAsync (searchText, doc, { onProgress, onDone, maxResults = Infinity, yieldAfterItemCount = 10_000 }) {
|
||||||
// TODO: what is a good value for yieldAfterItemCount? (larger means faster results but also less responsive during search)
|
// TODO: what is a good value for yieldAfterItemCount? (larger means faster results but also less responsive during search)
|
||||||
const search = searchGenerator(searchText, doc, yieldAfterItemCount)
|
const search = searchGenerator(searchText, doc, yieldAfterItemCount)
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ describe('search', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const yieldAfterItemCount = 1
|
const yieldAfterItemCount = 1
|
||||||
searchAsync('4', doc, { onProgress, onDone }, yieldAfterItemCount)
|
searchAsync('4', doc, { onProgress, onDone, yieldAfterItemCount })
|
||||||
|
|
||||||
// should not have results right after creation, but only on the first next tick
|
// should not have results right after creation, but only on the first next tick
|
||||||
assert.deepStrictEqual(callbacks, [])
|
assert.deepStrictEqual(callbacks, [])
|
||||||
|
@ -83,7 +83,7 @@ describe('search', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const yieldAfterItemCount = 1 // very low so we can see whether actually cancelled
|
const yieldAfterItemCount = 1 // very low so we can see whether actually cancelled
|
||||||
const { cancel } = searchAsync('4', doc, { onProgress, onDone }, yieldAfterItemCount)
|
const { cancel } = searchAsync('4', doc, { onProgress, onDone, yieldAfterItemCount })
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -105,7 +105,7 @@ describe('search', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxResults = 10
|
const maxResults = 10
|
||||||
searchAsync('item', doc, { onDone }, 1000, maxResults)
|
searchAsync('item', doc, { onDone, maxResults })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should generate recursive search results from flat results', () => {
|
it('should generate recursive search results from flat results', () => {
|
||||||
|
|
Loading…
Reference in New Issue