@ztimson/utils 0.26.19 → 0.26.20
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/cache.d.ts +1 -0
- package/dist/index.cjs +6 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +6 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -423,8 +423,9 @@ class Cache {
|
|
|
423
423
|
__publicField(this, "store", {});
|
|
424
424
|
/** Whether cache is complete */
|
|
425
425
|
__publicField(this, "complete", false);
|
|
426
|
+
__publicField(this, "_loading");
|
|
426
427
|
/** Await initial loading */
|
|
427
|
-
__publicField(this, "loading");
|
|
428
|
+
__publicField(this, "loading", new Promise((r) => this._loading = r));
|
|
428
429
|
/**
|
|
429
430
|
* Get all cached items
|
|
430
431
|
* @return {T[]} Array of items
|
|
@@ -433,8 +434,6 @@ class Cache {
|
|
|
433
434
|
var _a, _b, _c, _d;
|
|
434
435
|
this.key = key;
|
|
435
436
|
this.options = options;
|
|
436
|
-
let done;
|
|
437
|
-
this.loading = new Promise((r) => done = r);
|
|
438
437
|
if (this.options.persistentStorage != null) {
|
|
439
438
|
if (typeof this.options.persistentStorage == "string")
|
|
440
439
|
this.options.persistentStorage = { storage: localStorage, key: this.options.persistentStorage };
|
|
@@ -444,7 +443,7 @@ class Cache {
|
|
|
444
443
|
const table = await persists.storage.createTable({ name: persists.key, key: this.key });
|
|
445
444
|
const rows = await table.getAll();
|
|
446
445
|
Object.assign(this.store, rows.reduce((acc, row) => ({ ...acc, [this.getKey(row)]: row }), {}));
|
|
447
|
-
|
|
446
|
+
this._loading();
|
|
448
447
|
})();
|
|
449
448
|
} else if (((_d = (_c = this.options.persistentStorage) == null ? void 0 : _c.storage) == null ? void 0 : _d.getItem) != void 0) {
|
|
450
449
|
const stored = this.options.persistentStorage.storage.getItem(this.options.persistentStorage.key);
|
|
@@ -452,8 +451,10 @@ class Cache {
|
|
|
452
451
|
Object.assign(this.store, JSON.parse(stored));
|
|
453
452
|
} catch {
|
|
454
453
|
}
|
|
455
|
-
|
|
454
|
+
this._loading();
|
|
456
455
|
}
|
|
456
|
+
} else {
|
|
457
|
+
this._loading();
|
|
457
458
|
}
|
|
458
459
|
return new Proxy(this, {
|
|
459
460
|
get: (target, prop) => {
|