From 6fb6bc68e6ed93a02418a9358fc9e8ccdf651cf6 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 23 Sep 2020 08:18:32 +0200 Subject: [PATCH] Rename onProgress callback --- src/logic/search.js | 4 ++-- src/logic/search.test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/logic/search.js b/src/logic/search.js index 6452ce4..bdd4d34 100644 --- a/src/logic/search.js +++ b/src/logic/search.js @@ -135,7 +135,7 @@ async function tick () { } // TODO: comment -export function searchAsync (searchText, doc, { onPartlyResults, onDone }) { +export function searchAsync (searchText, doc, { onProgress, onDone }) { const yieldAfterItemCount = 10000 // TODO: what is a good value? const search = searchGenerator(searchText, doc, yieldAfterItemCount) @@ -150,7 +150,7 @@ export function searchAsync (searchText, doc, { onPartlyResults, onDone }) { next = search.next() if (next.value) { results.push(next.value) // TODO: make this immutable? - onPartlyResults(results) + onProgress(results) } await tick() // TODO: be able to wait longer than just one tick? So the UI stays fully responsive? } while (!cancelled && !next.done) diff --git a/src/logic/search.test.js b/src/logic/search.test.js index e7d087c..ba2e983 100644 --- a/src/logic/search.test.js +++ b/src/logic/search.test.js @@ -42,7 +42,7 @@ describe('search', () => { const callbacks = [] - function onPartlyResults (results) { + function onProgress (results) { callbacks.push(results.slice(0)) } @@ -62,7 +62,7 @@ describe('search', () => { done() } - searchAsync('4', doc, { onPartlyResults, onDone }) + searchAsync('4', doc, { onProgress, onDone }) // should not have results right after creation, but only on the first next tick assert.deepStrictEqual(callbacks, []) @@ -73,7 +73,7 @@ describe('search', () => { const callbacks = [] - function onPartlyResults (results) { + function onProgress (results) { callbacks.push(results.slice(0)) } @@ -81,7 +81,7 @@ describe('search', () => { throw new Error('onDone should not be invoked') } - const { cancel } = searchAsync('4', doc, { onPartlyResults, onDone }) + const { cancel } = searchAsync('4', doc, { onProgress, onDone }) // should not have results right after creation, but only on the first next tick assert.deepStrictEqual(callbacks, [])