venue-js 1.0.0-2 → 1.0.0-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -402,23 +402,33 @@ var getDataClient = (options) => {
|
|
|
402
402
|
};
|
|
403
403
|
const populator = createPopulator({ internalFindById, internalFilterByType });
|
|
404
404
|
const registerObserver = (featureType, refetchInterval) => {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const
|
|
408
|
-
observer
|
|
409
|
-
...options2,
|
|
410
|
-
refetchInterval
|
|
411
|
-
});
|
|
412
|
-
observers.set(featureType, observer);
|
|
413
|
-
} else {
|
|
414
|
-
console.warn(
|
|
415
|
-
`An observer for featureType ${featureType} already exists, fail to register new one`
|
|
416
|
-
);
|
|
405
|
+
if (observers.has(featureType)) {
|
|
406
|
+
console.warn(`Observer for ${featureType} already exists`);
|
|
407
|
+
const record = observers.get(featureType);
|
|
408
|
+
return record.observer;
|
|
417
409
|
}
|
|
410
|
+
const options2 = createDeliveryApiQueryOptions(featureType);
|
|
411
|
+
const observer = new QueryObserver(queryClient, {
|
|
412
|
+
...options2,
|
|
413
|
+
refetchInterval
|
|
414
|
+
});
|
|
415
|
+
const unsubscribe = observer.subscribe(() => {
|
|
416
|
+
console.log(`[venue-js] Listening to ${featureType} changes (interval = ${refetchInterval}ms)`);
|
|
417
|
+
});
|
|
418
|
+
observers.set(featureType, { observer, unsubscribe });
|
|
418
419
|
return observer;
|
|
419
420
|
};
|
|
421
|
+
const destroyObserver = (featureType) => {
|
|
422
|
+
const record = observers.get(featureType);
|
|
423
|
+
if (!record) return;
|
|
424
|
+
record.unsubscribe();
|
|
425
|
+
observers.delete(featureType);
|
|
426
|
+
};
|
|
420
427
|
const destroyObservers = () => {
|
|
421
|
-
observers.forEach((
|
|
428
|
+
observers.forEach(({ observer, unsubscribe }) => {
|
|
429
|
+
unsubscribe();
|
|
430
|
+
observer.destroy();
|
|
431
|
+
});
|
|
422
432
|
observers.clear();
|
|
423
433
|
};
|
|
424
434
|
const createFilterByTypeQueryOptions = (featureType, params = {}, options2 = {}) => ({
|
|
@@ -458,6 +468,7 @@ var getDataClient = (options) => {
|
|
|
458
468
|
projectId,
|
|
459
469
|
queryClient,
|
|
460
470
|
registerObserver,
|
|
471
|
+
destroyObserver,
|
|
461
472
|
destroyObservers,
|
|
462
473
|
createFilterByTypeQueryOptions,
|
|
463
474
|
createFindByIdQueryOptions,
|