@oimdb/react 1.1.1 → 1.2.1
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/README.md +204 -40
- package/dist/index.cjs +214 -162
- package/dist/index.d.cts +17 -13
- package/dist/index.d.ts +17 -13
- package/dist/index.js +207 -159
- package/package.json +14 -2
package/dist/index.cjs
CHANGED
|
@@ -24,12 +24,16 @@ __export(index_exports, {
|
|
|
24
24
|
OIMRICollectionsProvider: () => OIMRICollectionsProvider,
|
|
25
25
|
createOIMCollectionsContext: () => createOIMCollectionsContext,
|
|
26
26
|
useOIMCollectionsContext: () => useOIMCollectionsContext,
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
useSelectEntitiesByIndexKeyArrayBased: () => useSelectEntitiesByIndexKeyArrayBased,
|
|
28
|
+
useSelectEntitiesByIndexKeySetBased: () => useSelectEntitiesByIndexKeySetBased,
|
|
29
|
+
useSelectEntitiesByIndexKeysArrayBased: () => useSelectEntitiesByIndexKeysArrayBased,
|
|
30
|
+
useSelectEntitiesByIndexKeysSetBased: () => useSelectEntitiesByIndexKeysSetBased,
|
|
29
31
|
useSelectEntitiesByPks: () => useSelectEntitiesByPks,
|
|
30
32
|
useSelectEntityByPk: () => useSelectEntityByPk,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
useSelectPksByIndexKeyArrayBased: () => useSelectPksByIndexKeyArrayBased,
|
|
34
|
+
useSelectPksByIndexKeySetBased: () => useSelectPksByIndexKeySetBased,
|
|
35
|
+
useSelectPksByIndexKeysArrayBased: () => useSelectPksByIndexKeysArrayBased,
|
|
36
|
+
useSelectPksByIndexKeysSetBased: () => useSelectPksByIndexKeysSetBased
|
|
33
37
|
});
|
|
34
38
|
module.exports = __toCommonJS(index_exports);
|
|
35
39
|
|
|
@@ -37,215 +41,259 @@ module.exports = __toCommonJS(index_exports);
|
|
|
37
41
|
var import_react = require("react");
|
|
38
42
|
var import_react2 = require("react");
|
|
39
43
|
var EMPTY_ARRAY = [];
|
|
40
|
-
var
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const subscribe = (0, import_react.
|
|
48
|
-
|
|
49
|
-
return () => {
|
|
50
|
-
|
|
44
|
+
var useSelectPksByIndexKeysSetBased = (reactiveIndex, keys) => {
|
|
45
|
+
const prevKeysRef = (0, import_react.useRef)();
|
|
46
|
+
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
47
|
+
if (!keysAreEqual) {
|
|
48
|
+
prevKeysRef.current = keys;
|
|
49
|
+
}
|
|
50
|
+
const snapshotValueRef = (0, import_react.useRef)();
|
|
51
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
52
|
+
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
53
|
+
return (onStoreChange) => {
|
|
54
|
+
const prevKeys = prevKeysRef.current;
|
|
55
|
+
if (!prevKeys) {
|
|
56
|
+
return () => {
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const updateSnapshot = () => {
|
|
60
|
+
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
61
|
+
onStoreChange();
|
|
62
|
+
};
|
|
63
|
+
reactiveIndex.updateEventEmitter.subscribeOnKeys(
|
|
64
|
+
prevKeys,
|
|
65
|
+
updateSnapshot
|
|
66
|
+
);
|
|
67
|
+
return () => {
|
|
68
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(
|
|
69
|
+
prevKeys,
|
|
70
|
+
updateSnapshot
|
|
71
|
+
);
|
|
51
72
|
};
|
|
52
73
|
};
|
|
53
|
-
});
|
|
54
|
-
(0, import_react.useEffect)(() => {
|
|
55
|
-
const list = () => {
|
|
56
|
-
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
57
|
-
osc.current();
|
|
58
|
-
};
|
|
59
|
-
reactiveIndex.updateEventEmitter.subscribeOnKeys(keys, list);
|
|
60
|
-
if (!isInitialized.current) {
|
|
61
|
-
isInitialized.current = true;
|
|
62
|
-
} else {
|
|
63
|
-
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
64
|
-
osc.current();
|
|
65
|
-
}
|
|
66
|
-
return () => {
|
|
67
|
-
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(keys, list);
|
|
68
|
-
};
|
|
69
|
-
}, [keys, reactiveIndex.updateEventEmitter, reactiveIndex]);
|
|
74
|
+
}, [prevKeysRef.current, reactiveIndex.updateEventEmitter]);
|
|
70
75
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
71
76
|
return () => {
|
|
72
77
|
return snapshotValueRef.current;
|
|
73
78
|
};
|
|
74
79
|
}, []);
|
|
75
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
76
|
-
subscribe.current,
|
|
77
|
-
getSnapshot,
|
|
78
|
-
getSnapshot
|
|
79
|
-
);
|
|
80
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
80
81
|
return snapshot;
|
|
81
82
|
};
|
|
82
|
-
var
|
|
83
|
-
const
|
|
84
|
-
const snapshotValueRef = (0, import_react.useRef)(
|
|
85
|
-
Array.from(reactiveIndex.getPksByKey(key))
|
|
86
|
-
);
|
|
87
|
-
const osc = (0, import_react.useRef)(() => {
|
|
88
|
-
});
|
|
89
|
-
const subscribe = (0, import_react.useRef)((onStoreChange) => {
|
|
90
|
-
osc.current = onStoreChange;
|
|
83
|
+
var useSelectPksByIndexKeySetBased = (reactiveIndex, key) => {
|
|
84
|
+
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
91
85
|
return () => {
|
|
92
|
-
|
|
86
|
+
return reactiveIndex.getPksByKey(key);
|
|
87
|
+
};
|
|
88
|
+
}, [key, reactiveIndex]);
|
|
89
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
90
|
+
return (onStoreChange) => {
|
|
91
|
+
reactiveIndex.updateEventEmitter.subscribeOnKey(key, onStoreChange);
|
|
92
|
+
return () => {
|
|
93
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKey(
|
|
94
|
+
key,
|
|
95
|
+
onStoreChange
|
|
96
|
+
);
|
|
93
97
|
};
|
|
94
98
|
};
|
|
95
|
-
});
|
|
96
|
-
(0,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
}, [key, reactiveIndex.updateEventEmitter]);
|
|
100
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
101
|
+
return snapshot;
|
|
102
|
+
};
|
|
103
|
+
var useSelectPksByIndexKeysArrayBased = (reactiveIndex, keys) => {
|
|
104
|
+
const prevKeysRef = (0, import_react.useRef)();
|
|
105
|
+
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
106
|
+
if (!keysAreEqual) {
|
|
107
|
+
prevKeysRef.current = keys;
|
|
108
|
+
}
|
|
109
|
+
const snapshotValueRef = (0, import_react.useRef)();
|
|
110
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
111
|
+
snapshotValueRef.current = keys.map((key) => reactiveIndex.getPksByKey(key)).flat();
|
|
112
|
+
return (onStoreChange) => {
|
|
113
|
+
const prevKeys = prevKeysRef.current;
|
|
114
|
+
if (!prevKeys) {
|
|
115
|
+
return () => {
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const updateSnapshot = () => {
|
|
119
|
+
snapshotValueRef.current = keys.map((key) => reactiveIndex.getPksByKey(key)).flat();
|
|
120
|
+
onStoreChange();
|
|
121
|
+
};
|
|
122
|
+
reactiveIndex.updateEventEmitter.subscribeOnKeys(
|
|
123
|
+
prevKeys,
|
|
124
|
+
updateSnapshot
|
|
100
125
|
);
|
|
101
|
-
|
|
126
|
+
return () => {
|
|
127
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(
|
|
128
|
+
prevKeys,
|
|
129
|
+
updateSnapshot
|
|
130
|
+
);
|
|
131
|
+
};
|
|
102
132
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
isInitialized.current = true;
|
|
106
|
-
} else {
|
|
107
|
-
snapshotValueRef.current = Array.from(
|
|
108
|
-
reactiveIndex.getPksByKey(key)
|
|
109
|
-
);
|
|
110
|
-
osc.current();
|
|
111
|
-
}
|
|
133
|
+
}, [prevKeysRef.current, reactiveIndex.updateEventEmitter]);
|
|
134
|
+
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
112
135
|
return () => {
|
|
113
|
-
|
|
136
|
+
return snapshotValueRef.current;
|
|
114
137
|
};
|
|
115
|
-
}, [
|
|
138
|
+
}, []);
|
|
139
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
140
|
+
return snapshot;
|
|
141
|
+
};
|
|
142
|
+
var useSelectPksByIndexKeyArrayBased = (reactiveIndex, key) => {
|
|
143
|
+
const prevKeyRef = (0, import_react.useRef)();
|
|
144
|
+
const keyAreEqual = prevKeyRef.current === key;
|
|
145
|
+
if (!keyAreEqual) {
|
|
146
|
+
prevKeyRef.current = key;
|
|
147
|
+
}
|
|
148
|
+
const snapshotValueRef = (0, import_react.useRef)();
|
|
149
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
150
|
+
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
151
|
+
return (onStoreChange) => {
|
|
152
|
+
const prevKey = prevKeyRef.current;
|
|
153
|
+
if (!prevKey) {
|
|
154
|
+
return () => {
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const updateSnapshot = () => {
|
|
158
|
+
snapshotValueRef.current = reactiveIndex.getPksByKey(prevKey);
|
|
159
|
+
onStoreChange();
|
|
160
|
+
};
|
|
161
|
+
reactiveIndex.updateEventEmitter.subscribeOnKey(
|
|
162
|
+
prevKey,
|
|
163
|
+
updateSnapshot
|
|
164
|
+
);
|
|
165
|
+
return () => {
|
|
166
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKey(
|
|
167
|
+
prevKey,
|
|
168
|
+
updateSnapshot
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}, [key, reactiveIndex.updateEventEmitter]);
|
|
116
173
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
117
174
|
return () => {
|
|
118
175
|
return snapshotValueRef.current;
|
|
119
176
|
};
|
|
120
177
|
}, []);
|
|
121
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
122
|
-
subscribe.current,
|
|
123
|
-
getSnapshot,
|
|
124
|
-
getSnapshot
|
|
125
|
-
);
|
|
178
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
126
179
|
return snapshot;
|
|
127
180
|
};
|
|
128
181
|
var useSelectEntityByPk = (reactiveCollection, pk) => {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
reactiveCollection
|
|
182
|
+
const getSnapshot = (0, import_react.useMemo)(
|
|
183
|
+
() => () => reactiveCollection.getOneByPk(pk),
|
|
184
|
+
[pk, reactiveCollection]
|
|
132
185
|
);
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
186
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
187
|
+
return (onStoreChange) => {
|
|
188
|
+
reactiveCollection.updateEventEmitter.subscribeOnKey(
|
|
189
|
+
pk,
|
|
190
|
+
onStoreChange
|
|
191
|
+
);
|
|
192
|
+
return () => {
|
|
193
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKey(
|
|
194
|
+
pk,
|
|
195
|
+
onStoreChange
|
|
196
|
+
);
|
|
139
197
|
};
|
|
140
198
|
};
|
|
141
|
-
});
|
|
142
|
-
(0,
|
|
143
|
-
const list = () => {
|
|
144
|
-
snapshotValueRef.current = reactiveCollection.getOneByPk(pk);
|
|
145
|
-
osc.current();
|
|
146
|
-
};
|
|
147
|
-
reactiveCollection.updateEventEmitter.subscribeOnKey(pk, list);
|
|
148
|
-
if (!isInitialized.current) {
|
|
149
|
-
isInitialized.current = true;
|
|
150
|
-
} else {
|
|
151
|
-
snapshotValueRef.current = reactiveCollection.getOneByPk(pk);
|
|
152
|
-
osc.current();
|
|
153
|
-
}
|
|
154
|
-
return () => {
|
|
155
|
-
reactiveCollection.updateEventEmitter.unsubscribeFromKey(pk, list);
|
|
156
|
-
};
|
|
157
|
-
}, [pk, reactiveCollection.updateEventEmitter, reactiveCollection]);
|
|
158
|
-
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
|
|
159
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
160
|
-
subscribe.current,
|
|
161
|
-
getSnapshot,
|
|
162
|
-
getSnapshot
|
|
163
|
-
);
|
|
199
|
+
}, [pk, reactiveCollection.updateEventEmitter]);
|
|
200
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
164
201
|
return snapshot;
|
|
165
202
|
};
|
|
203
|
+
function arraysEqual(a, b) {
|
|
204
|
+
if (a === b) return true;
|
|
205
|
+
if (a.length !== b.length) return false;
|
|
206
|
+
for (let i = 0; i < a.length; i++) {
|
|
207
|
+
if (a[i] !== b[i]) return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
166
211
|
var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const subscribe = (0, import_react.
|
|
174
|
-
|
|
175
|
-
return () => {
|
|
176
|
-
|
|
212
|
+
const prevPksRef = (0, import_react.useRef)();
|
|
213
|
+
const pksAreEqual = arraysEqual(prevPksRef.current || EMPTY_ARRAY, pks);
|
|
214
|
+
if (!pksAreEqual) {
|
|
215
|
+
prevPksRef.current = pks;
|
|
216
|
+
}
|
|
217
|
+
const snapshotRef = (0, import_react.useRef)();
|
|
218
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
219
|
+
snapshotRef.current = pks.map((pk) => reactiveCollection.getOneByPk(pk));
|
|
220
|
+
return (onStoreChange) => {
|
|
221
|
+
const prevPks = prevPksRef.current;
|
|
222
|
+
if (!prevPks) {
|
|
223
|
+
return () => {
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const updateSnapshot = () => {
|
|
227
|
+
snapshotRef.current = prevPks.map(
|
|
228
|
+
(pk) => reactiveCollection.getOneByPk(pk)
|
|
229
|
+
);
|
|
230
|
+
onStoreChange();
|
|
177
231
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const list = () => {
|
|
182
|
-
snapshotValueRef.current = pks.map(
|
|
183
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
184
|
-
);
|
|
185
|
-
osc.current();
|
|
186
|
-
};
|
|
187
|
-
reactiveCollection.updateEventEmitter.subscribeOnKeys(pks, list);
|
|
188
|
-
if (!isInitialized.current) {
|
|
189
|
-
isInitialized.current = true;
|
|
190
|
-
} else {
|
|
191
|
-
snapshotValueRef.current = pks.map(
|
|
192
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
193
|
-
);
|
|
194
|
-
osc.current();
|
|
195
|
-
}
|
|
196
|
-
return () => {
|
|
197
|
-
reactiveCollection.updateEventEmitter.unsubscribeFromKeys(
|
|
198
|
-
pks,
|
|
199
|
-
list
|
|
232
|
+
reactiveCollection.updateEventEmitter.subscribeOnKeys(
|
|
233
|
+
prevPks,
|
|
234
|
+
updateSnapshot
|
|
200
235
|
);
|
|
236
|
+
return () => {
|
|
237
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKeys(
|
|
238
|
+
prevPks,
|
|
239
|
+
updateSnapshot
|
|
240
|
+
);
|
|
241
|
+
};
|
|
201
242
|
};
|
|
202
|
-
}, [
|
|
243
|
+
}, [prevPksRef.current, reactiveCollection.updateEventEmitter]);
|
|
203
244
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
204
245
|
return () => {
|
|
205
|
-
return
|
|
246
|
+
return snapshotRef.current;
|
|
206
247
|
};
|
|
207
248
|
}, []);
|
|
208
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
209
|
-
subscribe.current,
|
|
210
|
-
getSnapshot,
|
|
211
|
-
getSnapshot
|
|
212
|
-
);
|
|
249
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
213
250
|
return snapshot;
|
|
214
251
|
};
|
|
215
|
-
var
|
|
216
|
-
const pks =
|
|
252
|
+
var useSelectEntitiesByIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
|
|
253
|
+
const pks = useSelectPksByIndexKeySetBased(reactiveIndex, key);
|
|
254
|
+
const pksArray = (0, import_react.useMemo)(
|
|
255
|
+
() => pks ? Array.from(pks) : EMPTY_ARRAY,
|
|
256
|
+
[pks]
|
|
257
|
+
);
|
|
258
|
+
return useSelectEntitiesByPks(reactiveCollection, pksArray);
|
|
259
|
+
};
|
|
260
|
+
var useSelectEntitiesByIndexKeysSetBased = (reactiveCollection, reactiveIndex, keys) => {
|
|
261
|
+
const pks = useSelectPksByIndexKeysSetBased(reactiveIndex, keys);
|
|
262
|
+
const pksArray = (0, import_react.useMemo)(
|
|
263
|
+
() => pks ? Array.from(pks) : EMPTY_ARRAY,
|
|
264
|
+
[pks]
|
|
265
|
+
);
|
|
266
|
+
return useSelectEntitiesByPks(reactiveCollection, pksArray);
|
|
267
|
+
};
|
|
268
|
+
var useSelectEntitiesByIndexKeyArrayBased = (reactiveCollection, reactiveIndex, key) => {
|
|
269
|
+
const pks = useSelectPksByIndexKeyArrayBased(reactiveIndex, key);
|
|
217
270
|
return useSelectEntitiesByPks(
|
|
218
271
|
reactiveCollection,
|
|
219
272
|
pks || EMPTY_ARRAY
|
|
220
273
|
);
|
|
221
274
|
};
|
|
222
|
-
var
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var useSelectEntitiesByIndexKeys = (reactiveCollection, reactiveIndex, keys) => {
|
|
226
|
-
const pks = useSelectPksByIndexKeys(reactiveIndex, keys) || EMPTY_ARRAY;
|
|
227
|
-
return useSelectEntitiesByPks(reactiveCollection, unique(Array.from(pks)));
|
|
275
|
+
var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex, keys) => {
|
|
276
|
+
const pks = useSelectPksByIndexKeysArrayBased(reactiveIndex, keys) || EMPTY_ARRAY;
|
|
277
|
+
return useSelectEntitiesByPks(reactiveCollection, pks);
|
|
228
278
|
};
|
|
229
279
|
|
|
230
280
|
// src/context/index.tsx
|
|
231
281
|
var import_react3 = require("react");
|
|
232
282
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
233
|
-
var OIMRICollectionsContext = (0, import_react3.createContext)(
|
|
283
|
+
var OIMRICollectionsContext = (0, import_react3.createContext)(
|
|
284
|
+
{}
|
|
285
|
+
);
|
|
234
286
|
function createOIMCollectionsContext() {
|
|
235
|
-
return (0, import_react3.createContext)(
|
|
287
|
+
return (0, import_react3.createContext)({});
|
|
236
288
|
}
|
|
237
|
-
function OIMRICollectionsProvider({
|
|
238
|
-
|
|
239
|
-
children
|
|
240
|
-
context = OIMRICollectionsContext
|
|
241
|
-
}) {
|
|
242
|
-
const Provider = context.Provider;
|
|
243
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, { value: collections, children });
|
|
289
|
+
function OIMRICollectionsProvider({ collections, children, context }) {
|
|
290
|
+
const ContextToUse = context || OIMRICollectionsContext;
|
|
291
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextToUse.Provider, { value: collections, children });
|
|
244
292
|
}
|
|
245
293
|
function useOIMCollectionsContext(context) {
|
|
246
294
|
const contextToUse = context || OIMRICollectionsContext;
|
|
247
295
|
const collections = (0, import_react3.useContext)(contextToUse);
|
|
248
|
-
if (!collections) {
|
|
296
|
+
if (!collections || Object.keys(collections).length === 0) {
|
|
249
297
|
throw new Error(
|
|
250
298
|
"useOIMCollectionsContext must be used within an OIMRICollectionsProvider"
|
|
251
299
|
);
|
|
@@ -258,10 +306,14 @@ function useOIMCollectionsContext(context) {
|
|
|
258
306
|
OIMRICollectionsProvider,
|
|
259
307
|
createOIMCollectionsContext,
|
|
260
308
|
useOIMCollectionsContext,
|
|
261
|
-
|
|
262
|
-
|
|
309
|
+
useSelectEntitiesByIndexKeyArrayBased,
|
|
310
|
+
useSelectEntitiesByIndexKeySetBased,
|
|
311
|
+
useSelectEntitiesByIndexKeysArrayBased,
|
|
312
|
+
useSelectEntitiesByIndexKeysSetBased,
|
|
263
313
|
useSelectEntitiesByPks,
|
|
264
314
|
useSelectEntityByPk,
|
|
265
|
-
|
|
266
|
-
|
|
315
|
+
useSelectPksByIndexKeyArrayBased,
|
|
316
|
+
useSelectPksByIndexKeySetBased,
|
|
317
|
+
useSelectPksByIndexKeysArrayBased,
|
|
318
|
+
useSelectPksByIndexKeysSetBased
|
|
267
319
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { TOIMPk,
|
|
1
|
+
import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMRICollection } from '@oimdb/core';
|
|
2
2
|
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
|
|
7
|
-
declare const
|
|
6
|
+
declare const useSelectPksByIndexKeysSetBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => TPk[] | undefined;
|
|
7
|
+
declare const useSelectPksByIndexKeySetBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => Set<TPk>;
|
|
8
|
+
declare const useSelectPksByIndexKeysArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => TPk[] | undefined;
|
|
9
|
+
declare const useSelectPksByIndexKeyArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => TPk[] | undefined;
|
|
8
10
|
declare const useSelectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
|
|
9
|
-
declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => readonly TEntity[] |
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
11
|
+
declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => readonly (TEntity | undefined)[] | undefined;
|
|
12
|
+
declare const useSelectEntitiesByIndexKeySetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
|
|
13
|
+
declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
|
|
14
|
+
declare const useSelectEntitiesByIndexKeyArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
|
|
15
|
+
declare const useSelectEntitiesByIndexKeysArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
|
|
12
16
|
|
|
13
|
-
type CollectionsDictionary = Record<string, OIMRICollection<
|
|
14
|
-
type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T
|
|
15
|
-
declare const OIMRICollectionsContext: React.Context<
|
|
16
|
-
declare function createOIMCollectionsContext<T extends CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
|
|
17
|
-
interface OIMRICollectionsProviderProps<T extends CollectionsDictionary> {
|
|
17
|
+
type CollectionsDictionary = Record<string, OIMRICollection<any, any, any, any>>;
|
|
18
|
+
type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
|
|
19
|
+
declare const OIMRICollectionsContext: React.Context<CollectionsDictionary>;
|
|
20
|
+
declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
|
|
21
|
+
interface OIMRICollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
|
|
18
22
|
collections: T;
|
|
19
23
|
children: ReactNode;
|
|
20
24
|
context?: React.Context<OIMContextValue<T>>;
|
|
21
25
|
}
|
|
22
|
-
declare function OIMRICollectionsProvider<T extends CollectionsDictionary>({ collections, children, context
|
|
26
|
+
declare function OIMRICollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
|
|
23
27
|
declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
|
|
24
28
|
|
|
25
|
-
export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext,
|
|
29
|
+
export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { TOIMPk,
|
|
1
|
+
import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMRICollection } from '@oimdb/core';
|
|
2
2
|
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
|
|
7
|
-
declare const
|
|
6
|
+
declare const useSelectPksByIndexKeysSetBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => TPk[] | undefined;
|
|
7
|
+
declare const useSelectPksByIndexKeySetBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => Set<TPk>;
|
|
8
|
+
declare const useSelectPksByIndexKeysArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => TPk[] | undefined;
|
|
9
|
+
declare const useSelectPksByIndexKeyArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => TPk[] | undefined;
|
|
8
10
|
declare const useSelectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
|
|
9
|
-
declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => readonly TEntity[] |
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
11
|
+
declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => readonly (TEntity | undefined)[] | undefined;
|
|
12
|
+
declare const useSelectEntitiesByIndexKeySetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
|
|
13
|
+
declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
|
|
14
|
+
declare const useSelectEntitiesByIndexKeyArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
|
|
15
|
+
declare const useSelectEntitiesByIndexKeysArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
|
|
12
16
|
|
|
13
|
-
type CollectionsDictionary = Record<string, OIMRICollection<
|
|
14
|
-
type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T
|
|
15
|
-
declare const OIMRICollectionsContext: React.Context<
|
|
16
|
-
declare function createOIMCollectionsContext<T extends CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
|
|
17
|
-
interface OIMRICollectionsProviderProps<T extends CollectionsDictionary> {
|
|
17
|
+
type CollectionsDictionary = Record<string, OIMRICollection<any, any, any, any>>;
|
|
18
|
+
type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
|
|
19
|
+
declare const OIMRICollectionsContext: React.Context<CollectionsDictionary>;
|
|
20
|
+
declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
|
|
21
|
+
interface OIMRICollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
|
|
18
22
|
collections: T;
|
|
19
23
|
children: ReactNode;
|
|
20
24
|
context?: React.Context<OIMContextValue<T>>;
|
|
21
25
|
}
|
|
22
|
-
declare function OIMRICollectionsProvider<T extends CollectionsDictionary>({ collections, children, context
|
|
26
|
+
declare function OIMRICollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
|
|
23
27
|
declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
|
|
24
28
|
|
|
25
|
-
export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext,
|
|
29
|
+
export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased };
|