Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 279f2bb

Browse files
committed
feat(store): allow to wait for the store to be in sync
1 parent 90f5347 commit 279f2bb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/store.js

+19
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,23 @@ export class Store {
337337
refresh() {
338338
this._helper.search();
339339
}
340+
341+
waitUntilInSync() {
342+
return new Promise((resolve, reject) => {
343+
if (this._helper.hasPendingRequests() === false) {
344+
return resolve();
345+
}
346+
347+
// Todo: we need to de-register the one that is not being triggered.
348+
this._helper.once('searchQueueEmpty', () => {
349+
resolve();
350+
});
351+
this._helper.once('error', error => {
352+
throw new Error(error.message);
353+
// Todo: implement rejection once this has a solution
354+
// https://github.com/algolia/algoliasearch-helper-js/issues/502
355+
// reject(error);
356+
});
357+
});
358+
}
340359
}

0 commit comments

Comments
 (0)