Refactor API of asyncSearch

This commit is contained in:
Jos de Jong 2020-10-10 14:11:38 +02:00
parent adda5836af
commit cc99284052
3 changed files with 7 additions and 6 deletions

View File

@ -125,8 +125,9 @@ findRootPath
searchHandler = searchAsync(searchText, doc, {
onProgress: handleSearchProgressDebounced,
onDone: handleSearchDone
}, 10000, MAX_SEARCH_RESULTS)
onDone: handleSearchDone,
maxResults: MAX_SEARCH_RESULTS
})
}
const history = createHistory({

View File

@ -109,7 +109,7 @@ async function tick () {
}
// 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)
const search = searchGenerator(searchText, doc, yieldAfterItemCount)

View File

@ -63,7 +63,7 @@ describe('search', () => {
}
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
assert.deepStrictEqual(callbacks, [])
@ -83,7 +83,7 @@ describe('search', () => {
}
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(() => {
cancel()
@ -105,7 +105,7 @@ describe('search', () => {
}
const maxResults = 10
searchAsync('item', doc, { onDone }, 1000, maxResults)
searchAsync('item', doc, { onDone, maxResults })
})
it('should generate recursive search results from flat results', () => {