asma-helpers 0.7.4 → 0.8.0
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/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts +4 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts.map +1 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js +10 -4
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/InitializeIDBListenersOnMstSnapshots.ts +20 -5
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export declare function initiatieIDBListenersOnMstSnaphsots<T extends Object, K extends keyof T>(store: T, omit?: K[]):
|
|
1
|
+
export declare function initiatieIDBListenersOnMstSnaphsots<T extends Object, K extends keyof T>(store: T, omit?: K[]): {
|
|
2
|
+
idb_check_promise: Promise<void>;
|
|
3
|
+
unregisterAll: () => void;
|
|
4
|
+
};
|
|
2
5
|
//# sourceMappingURL=InitializeIDBListenersOnMstSnapshots.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitializeIDBListenersOnMstSnapshots.d.ts","sourceRoot":"","sources":["../../src/helpers/InitializeIDBListenersOnMstSnapshots.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InitializeIDBListenersOnMstSnapshots.d.ts","sourceRoot":"","sources":["../../src/helpers/InitializeIDBListenersOnMstSnapshots.ts"],"names":[],"mappings":"AA0CA,wBAAgB,mCAAmC,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,GAAE,CAAC,EAAO;;;EAQhH"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { del, get, set } from 'idb-keyval';
|
|
2
|
-
import { applySnapshot, onSnapshot, isStateTreeNode } from 'mobx-state-tree';
|
|
2
|
+
import { applySnapshot, onSnapshot, isStateTreeNode, } from 'mobx-state-tree';
|
|
3
3
|
function setIDBListenersOnSnapshots(store, omit = []) {
|
|
4
4
|
const keys = Object.keys(store).filter((k) => !omit.includes(k));
|
|
5
|
+
const unregister_registry = [];
|
|
5
6
|
keys.forEach((key) => {
|
|
6
7
|
const mst_node = store[key];
|
|
7
8
|
if (isStateTreeNode(mst_node)) {
|
|
8
|
-
onSnapshot(mst_node, (snapshot) => {
|
|
9
|
+
const disposer = onSnapshot(mst_node, (snapshot) => {
|
|
9
10
|
set(String(key), snapshot).catch((e) => console.error(e));
|
|
10
11
|
});
|
|
12
|
+
unregister_registry.push(disposer);
|
|
11
13
|
}
|
|
12
14
|
});
|
|
15
|
+
return unregister_registry;
|
|
13
16
|
}
|
|
14
17
|
async function checkForIDBData(main_store) {
|
|
15
18
|
const keys = Object.keys(main_store);
|
|
@@ -22,8 +25,11 @@ async function checkForIDBData(main_store) {
|
|
|
22
25
|
await Promise.allSettled(promises);
|
|
23
26
|
}
|
|
24
27
|
export function initiatieIDBListenersOnMstSnaphsots(store, omit = []) {
|
|
25
|
-
setIDBListenersOnSnapshots(store, omit);
|
|
26
|
-
|
|
28
|
+
const unregister_registry = setIDBListenersOnSnapshots(store, omit);
|
|
29
|
+
function unregisterAll() {
|
|
30
|
+
unregister_registry.forEach((unregister) => unregister());
|
|
31
|
+
}
|
|
32
|
+
return { idb_check_promise: checkForIDBData(store), unregisterAll };
|
|
27
33
|
}
|
|
28
34
|
async function applySnapshotOnResolvedIDBGetPromise(key, main_store) {
|
|
29
35
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitializeIDBListenersOnMstSnapshots.js","sourceRoot":"","sources":["../../src/helpers/InitializeIDBListenersOnMstSnapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"InitializeIDBListenersOnMstSnapshots.js","sourceRo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TreeNode,
|
|
7
|
+
type IType,
|
|
8
|
+
type IDisposer,
|
|
9
|
+
} from 'mobx-state-tree'
|
|
10
|
+
|
|
3
11
|
function setIDBListenersOnSnapshots<T extends Object, K extends keyof T>(store: T, omit: K[] = []) {
|
|
4
12
|
const keys = (Object.keys(store) as Array<keyof typeof store>).filter((k) => !omit.includes(k as K))
|
|
5
13
|
|
|
14
|
+
const unregister_registry: IDisposer[] = []
|
|
15
|
+
|
|
6
16
|
keys.forEach((key) => {
|
|
7
17
|
const mst_node = store[key]
|
|
8
18
|
|
|
9
19
|
if (isStateTreeNode(mst_node)) {
|
|
10
|
-
onSnapshot(mst_node, (snapshot) => {
|
|
20
|
+
const disposer = onSnapshot(mst_node, (snapshot) => {
|
|
11
21
|
set(String(key), snapshot).catch((e) => console.error(e))
|
|
12
22
|
})
|
|
23
|
+
unregister_registry.push(disposer)
|
|
13
24
|
}
|
|
14
25
|
})
|
|
26
|
+
return unregister_registry
|
|
15
27
|
}
|
|
16
28
|
|
|
17
29
|
async function checkForIDBData<T extends Object>(main_store: T) {
|
|
@@ -29,9 +41,13 @@ async function checkForIDBData<T extends Object>(main_store: T) {
|
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
export function initiatieIDBListenersOnMstSnaphsots<T extends Object, K extends keyof T>(store: T, omit: K[] = []) {
|
|
32
|
-
setIDBListenersOnSnapshots(store, omit)
|
|
44
|
+
const unregister_registry = setIDBListenersOnSnapshots(store, omit)
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
function unregisterAll() {
|
|
47
|
+
unregister_registry.forEach((unregister) => unregister())
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { idb_check_promise: checkForIDBData(store), unregisterAll }
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
async function applySnapshotOnResolvedIDBGetPromise<T extends Object>(key: keyof T, main_store: T): Promise<void> {
|
|
@@ -47,4 +63,3 @@ async function applySnapshotOnResolvedIDBGetPromise<T extends Object>(key: keyof
|
|
|
47
63
|
console.error(`resolveIDBGetPromise, ${String(key)}:`, e)
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
|
-
|