@ztimson/utils 0.25.20 → 0.25.22
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 +2 -0
- package/dist/index.cjs +8 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +8 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare class Cache<K extends string | number | symbol, T> {
|
|
|
23
23
|
[key: string | number | symbol]: CachedValue<T> | any;
|
|
24
24
|
/** Whether cache is complete */
|
|
25
25
|
complete: boolean;
|
|
26
|
+
/** Await initial loading */
|
|
27
|
+
loading: Promise<void>;
|
|
26
28
|
/**
|
|
27
29
|
* Create new cache
|
|
28
30
|
* @param {keyof T} key Default property to use as primary key
|
package/dist/index.cjs
CHANGED
|
@@ -534,6 +534,8 @@ ${opts.message || this.desc}`;
|
|
|
534
534
|
__publicField(this, "store", {});
|
|
535
535
|
/** Whether cache is complete */
|
|
536
536
|
__publicField(this, "complete", false);
|
|
537
|
+
/** Await initial loading */
|
|
538
|
+
__publicField(this, "loading");
|
|
537
539
|
/**
|
|
538
540
|
* Get all cached items
|
|
539
541
|
* @return {T[]} Array of items
|
|
@@ -542,12 +544,15 @@ ${opts.message || this.desc}`;
|
|
|
542
544
|
var _a;
|
|
543
545
|
this.key = key;
|
|
544
546
|
this.options = options;
|
|
547
|
+
let resolve;
|
|
548
|
+
this.loading = new Promise((r) => resolve = r);
|
|
545
549
|
if (options.storageKey && !options.storage && typeof Storage !== "undefined") options.storage = localStorage;
|
|
546
550
|
if (options.storage) {
|
|
547
551
|
if (options.storage instanceof Table) {
|
|
548
552
|
(async () => {
|
|
549
553
|
var _a2;
|
|
550
|
-
|
|
554
|
+
this.addAll(await ((_a2 = options.storage) == null ? void 0 : _a2.getAll()), false);
|
|
555
|
+
resolve();
|
|
551
556
|
})();
|
|
552
557
|
} else if (options.storageKey) {
|
|
553
558
|
const stored = (_a = options.storage) == null ? void 0 : _a.getItem(options.storageKey);
|
|
@@ -555,8 +560,9 @@ ${opts.message || this.desc}`;
|
|
|
555
560
|
Object.assign(this.store, JSON.parse(stored));
|
|
556
561
|
} catch {
|
|
557
562
|
}
|
|
563
|
+
resolve();
|
|
558
564
|
}
|
|
559
|
-
}
|
|
565
|
+
} else resolve();
|
|
560
566
|
return new Proxy(this, {
|
|
561
567
|
get: (target, prop) => {
|
|
562
568
|
if (prop in target) return target[prop];
|