socket-function 0.8.10 → 0.8.11
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/mobx/promiseToObservable.tsx +2 -0
- package/package.json +1 -1
- package/src/caching.ts +5 -0
|
@@ -35,6 +35,7 @@ export function promiseToObservable<T>(promise: Promise<T>): { value: T | undefi
|
|
|
35
35
|
export function asyncObservable<Output, Key>(maxCount: number, getValue: (key: Key) => Promise<Output>): {
|
|
36
36
|
(key: Key): Output | undefined;
|
|
37
37
|
invalidate(key: Key): void;
|
|
38
|
+
invalidateAll(): void;
|
|
38
39
|
} {
|
|
39
40
|
let cache = cacheLimited(maxCount, (keyJSON: string) => {
|
|
40
41
|
let key = keyJSON ? JSON.parse(keyJSON) : keyJSON;
|
|
@@ -45,6 +46,7 @@ export function asyncObservable<Output, Key>(maxCount: number, getValue: (key: K
|
|
|
45
46
|
get["invalidate"] = (key: Key) => {
|
|
46
47
|
cache.invalidate(JSON.stringify(key));
|
|
47
48
|
};
|
|
49
|
+
get["invalidateAll"] = () => cache.invalidateAll();
|
|
48
50
|
function get(key: Key) {
|
|
49
51
|
return cache(JSON.stringify(key)).value;
|
|
50
52
|
}
|
package/package.json
CHANGED
package/src/caching.ts
CHANGED
|
@@ -67,6 +67,7 @@ export function cacheLimited<Output, Key>(
|
|
|
67
67
|
): {
|
|
68
68
|
(key: Key): Output;
|
|
69
69
|
invalidate(key: Key): void;
|
|
70
|
+
invalidateAll(): void;
|
|
70
71
|
} {
|
|
71
72
|
let startingCalculating = new Set<Key>();
|
|
72
73
|
let values = new Map<Key, Output>();
|
|
@@ -74,6 +75,10 @@ export function cacheLimited<Output, Key>(
|
|
|
74
75
|
values.delete(key);
|
|
75
76
|
startingCalculating.delete(key);
|
|
76
77
|
};
|
|
78
|
+
get["invalidateAll"] = () => {
|
|
79
|
+
values.clear();
|
|
80
|
+
startingCalculating.clear();
|
|
81
|
+
};
|
|
77
82
|
function get(input: Key) {
|
|
78
83
|
let key = input;
|
|
79
84
|
if (values.has(key)) {
|