@oimdb/react 1.0.1 → 1.0.2
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.cjs +34 -12
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -43,10 +43,17 @@ var useSelectPksByIndexKeys = (reactiveIndex, keys) => {
|
|
|
43
43
|
onStoreChange
|
|
44
44
|
);
|
|
45
45
|
}, [keys, reactiveIndex.updateEventEmitter]);
|
|
46
|
-
const getSnapshot = (0, import_react.useMemo)(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
47
|
+
let cachedResult = null;
|
|
48
|
+
let cachedKeys = null;
|
|
49
|
+
return () => {
|
|
50
|
+
if (cachedKeys !== keys || !cachedResult) {
|
|
51
|
+
cachedResult = keys.map((key) => reactiveIndex.getPksByKey(key));
|
|
52
|
+
cachedKeys = keys;
|
|
53
|
+
}
|
|
54
|
+
return cachedResult;
|
|
55
|
+
};
|
|
56
|
+
}, [keys, reactiveIndex]);
|
|
50
57
|
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
51
58
|
return snapshot;
|
|
52
59
|
};
|
|
@@ -82,10 +89,17 @@ var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
|
82
89
|
onStoreChange
|
|
83
90
|
);
|
|
84
91
|
}, [pks, reactiveCollection.updateEventEmitter]);
|
|
85
|
-
const getSnapshot = (0, import_react.useMemo)(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
93
|
+
let cachedResult = null;
|
|
94
|
+
let cachedPks = null;
|
|
95
|
+
return () => {
|
|
96
|
+
if (cachedPks !== pks || !cachedResult) {
|
|
97
|
+
cachedResult = pks.map((pk) => reactiveCollection.getOneByPk(pk));
|
|
98
|
+
cachedPks = pks;
|
|
99
|
+
}
|
|
100
|
+
return cachedResult;
|
|
101
|
+
};
|
|
102
|
+
}, [pks, reactiveCollection]);
|
|
89
103
|
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
90
104
|
return snapshot;
|
|
91
105
|
};
|
|
@@ -98,10 +112,18 @@ var unique = (array) => {
|
|
|
98
112
|
};
|
|
99
113
|
var selectEntitiesByIndexKeys = (reactiveCollection, reactiveIndex, keys) => {
|
|
100
114
|
const pks = useSelectPksByIndexKeys(reactiveIndex, keys);
|
|
101
|
-
const pksArray = (0, import_react.useMemo)(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
const pksArray = (0, import_react.useMemo)(() => {
|
|
116
|
+
let cachedResult = null;
|
|
117
|
+
let cachedPks = null;
|
|
118
|
+
const getCurrentPksArray = () => {
|
|
119
|
+
if (cachedPks !== pks || !cachedResult) {
|
|
120
|
+
cachedResult = unique(Array.from(pks.values()).flat());
|
|
121
|
+
cachedPks = pks;
|
|
122
|
+
}
|
|
123
|
+
return cachedResult;
|
|
124
|
+
};
|
|
125
|
+
return getCurrentPksArray();
|
|
126
|
+
}, [pks]);
|
|
105
127
|
return useSelectEntitiesByPks(reactiveCollection, pksArray);
|
|
106
128
|
};
|
|
107
129
|
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
|
-
declare const useSelectPksByIndexKeys: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>>(reactiveIndex: OIMReactiveIndex<TKey, TPk, TIndex>, keys: readonly TKey[]) => (readonly TPk[])[];
|
|
6
|
+
declare const useSelectPksByIndexKeys: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>>(reactiveIndex: OIMReactiveIndex<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (readonly TPk[])[];
|
|
7
7
|
declare const useSelectPksByIndexKey: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>>(reactiveIndex: OIMReactiveIndex<TKey, TPk, TIndex>, key: TKey) => readonly TPk[];
|
|
8
8
|
declare const selectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
|
|
9
9
|
declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => (TEntity | undefined)[];
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
|
-
declare const useSelectPksByIndexKeys: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>>(reactiveIndex: OIMReactiveIndex<TKey, TPk, TIndex>, keys: readonly TKey[]) => (readonly TPk[])[];
|
|
6
|
+
declare const useSelectPksByIndexKeys: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>>(reactiveIndex: OIMReactiveIndex<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (readonly TPk[])[];
|
|
7
7
|
declare const useSelectPksByIndexKey: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>>(reactiveIndex: OIMReactiveIndex<TKey, TPk, TIndex>, key: TKey) => readonly TPk[];
|
|
8
8
|
declare const selectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
|
|
9
9
|
declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => (TEntity | undefined)[];
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,17 @@ var useSelectPksByIndexKeys = (reactiveIndex, keys) => {
|
|
|
8
8
|
onStoreChange
|
|
9
9
|
);
|
|
10
10
|
}, [keys, reactiveIndex.updateEventEmitter]);
|
|
11
|
-
const getSnapshot = useMemo(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const getSnapshot = useMemo(() => {
|
|
12
|
+
let cachedResult = null;
|
|
13
|
+
let cachedKeys = null;
|
|
14
|
+
return () => {
|
|
15
|
+
if (cachedKeys !== keys || !cachedResult) {
|
|
16
|
+
cachedResult = keys.map((key) => reactiveIndex.getPksByKey(key));
|
|
17
|
+
cachedKeys = keys;
|
|
18
|
+
}
|
|
19
|
+
return cachedResult;
|
|
20
|
+
};
|
|
21
|
+
}, [keys, reactiveIndex]);
|
|
15
22
|
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
16
23
|
return snapshot;
|
|
17
24
|
};
|
|
@@ -47,10 +54,17 @@ var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
|
47
54
|
onStoreChange
|
|
48
55
|
);
|
|
49
56
|
}, [pks, reactiveCollection.updateEventEmitter]);
|
|
50
|
-
const getSnapshot = useMemo(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
const getSnapshot = useMemo(() => {
|
|
58
|
+
let cachedResult = null;
|
|
59
|
+
let cachedPks = null;
|
|
60
|
+
return () => {
|
|
61
|
+
if (cachedPks !== pks || !cachedResult) {
|
|
62
|
+
cachedResult = pks.map((pk) => reactiveCollection.getOneByPk(pk));
|
|
63
|
+
cachedPks = pks;
|
|
64
|
+
}
|
|
65
|
+
return cachedResult;
|
|
66
|
+
};
|
|
67
|
+
}, [pks, reactiveCollection]);
|
|
54
68
|
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
55
69
|
return snapshot;
|
|
56
70
|
};
|
|
@@ -63,10 +77,18 @@ var unique = (array) => {
|
|
|
63
77
|
};
|
|
64
78
|
var selectEntitiesByIndexKeys = (reactiveCollection, reactiveIndex, keys) => {
|
|
65
79
|
const pks = useSelectPksByIndexKeys(reactiveIndex, keys);
|
|
66
|
-
const pksArray = useMemo(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
const pksArray = useMemo(() => {
|
|
81
|
+
let cachedResult = null;
|
|
82
|
+
let cachedPks = null;
|
|
83
|
+
const getCurrentPksArray = () => {
|
|
84
|
+
if (cachedPks !== pks || !cachedResult) {
|
|
85
|
+
cachedResult = unique(Array.from(pks.values()).flat());
|
|
86
|
+
cachedPks = pks;
|
|
87
|
+
}
|
|
88
|
+
return cachedResult;
|
|
89
|
+
};
|
|
90
|
+
return getCurrentPksArray();
|
|
91
|
+
}, [pks]);
|
|
70
92
|
return useSelectEntitiesByPks(reactiveCollection, pksArray);
|
|
71
93
|
};
|
|
72
94
|
|