@oimdb/react 1.2.2 → 2.0.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/README.md +79 -721
- package/dist/index.cjs +213 -124
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +211 -122
- package/package.json +7 -4
package/dist/index.cjs
CHANGED
|
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
OIMCollectionsContext: () => OIMCollectionsContext,
|
|
24
|
+
OIMCollectionsProvider: () => OIMCollectionsProvider,
|
|
25
25
|
createOIMCollectionsContext: () => createOIMCollectionsContext,
|
|
26
26
|
useOIMCollectionsContext: () => useOIMCollectionsContext,
|
|
27
27
|
useSelectEntitiesByIndexKeyArrayBased: () => useSelectEntitiesByIndexKeyArrayBased,
|
|
@@ -49,31 +49,24 @@ var useSelectPksByIndexKeysSetBased = (reactiveIndex, keys) => {
|
|
|
49
49
|
if (!keysAreEqual) {
|
|
50
50
|
prevKeysRef.current = keys;
|
|
51
51
|
}
|
|
52
|
+
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
52
53
|
const snapshotValueRef = (0, import_react.useRef)();
|
|
53
54
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
54
|
-
snapshotValueRef.current =
|
|
55
|
+
snapshotValueRef.current = stableKeys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
55
56
|
return (onStoreChange) => {
|
|
56
|
-
const prevKeys = prevKeysRef.current;
|
|
57
|
-
if (!prevKeys) {
|
|
58
|
-
return () => {
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
57
|
const updateSnapshot = () => {
|
|
62
|
-
snapshotValueRef.current =
|
|
58
|
+
snapshotValueRef.current = stableKeys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
63
59
|
onStoreChange();
|
|
64
60
|
};
|
|
65
|
-
reactiveIndex.
|
|
66
|
-
|
|
61
|
+
const unsubscribe = reactiveIndex.subscribeOnKeys(
|
|
62
|
+
stableKeys,
|
|
67
63
|
updateSnapshot
|
|
68
64
|
);
|
|
69
65
|
return () => {
|
|
70
|
-
|
|
71
|
-
prevKeys,
|
|
72
|
-
updateSnapshot
|
|
73
|
-
);
|
|
66
|
+
unsubscribe();
|
|
74
67
|
};
|
|
75
68
|
};
|
|
76
|
-
}, [
|
|
69
|
+
}, [reactiveIndex, stableKeys]);
|
|
77
70
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
78
71
|
return () => {
|
|
79
72
|
return snapshotValueRef.current;
|
|
@@ -83,22 +76,22 @@ var useSelectPksByIndexKeysSetBased = (reactiveIndex, keys) => {
|
|
|
83
76
|
return snapshot;
|
|
84
77
|
};
|
|
85
78
|
var useSelectPksByIndexKeySetBased = (reactiveIndex, key) => {
|
|
86
|
-
const
|
|
87
|
-
return () => {
|
|
88
|
-
return reactiveIndex.getPksByKey(key);
|
|
89
|
-
};
|
|
90
|
-
}, [key, reactiveIndex]);
|
|
79
|
+
const snapshotValueRef = (0, import_react.useRef)();
|
|
91
80
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
81
|
+
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
92
82
|
return (onStoreChange) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
key,
|
|
97
|
-
onStoreChange
|
|
98
|
-
);
|
|
83
|
+
const updateSnapshot = () => {
|
|
84
|
+
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
85
|
+
onStoreChange();
|
|
99
86
|
};
|
|
87
|
+
return reactiveIndex.subscribeOnKey(key, updateSnapshot);
|
|
88
|
+
};
|
|
89
|
+
}, [key, reactiveIndex]);
|
|
90
|
+
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
91
|
+
return () => {
|
|
92
|
+
return snapshotValueRef.current;
|
|
100
93
|
};
|
|
101
|
-
}, [
|
|
94
|
+
}, []);
|
|
102
95
|
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
103
96
|
return snapshot;
|
|
104
97
|
};
|
|
@@ -108,31 +101,24 @@ var useSelectPksByIndexKeysArrayBased = (reactiveIndex, keys) => {
|
|
|
108
101
|
if (!keysAreEqual) {
|
|
109
102
|
prevKeysRef.current = keys;
|
|
110
103
|
}
|
|
104
|
+
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
111
105
|
const snapshotValueRef = (0, import_react.useRef)();
|
|
112
106
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
113
|
-
snapshotValueRef.current =
|
|
107
|
+
snapshotValueRef.current = stableKeys.map((key) => reactiveIndex.getPksByKey(key)).flat();
|
|
114
108
|
return (onStoreChange) => {
|
|
115
|
-
const prevKeys = prevKeysRef.current;
|
|
116
|
-
if (!prevKeys) {
|
|
117
|
-
return () => {
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
109
|
const updateSnapshot = () => {
|
|
121
|
-
snapshotValueRef.current =
|
|
110
|
+
snapshotValueRef.current = stableKeys.map((key) => reactiveIndex.getPksByKey(key)).flat();
|
|
122
111
|
onStoreChange();
|
|
123
112
|
};
|
|
124
|
-
reactiveIndex.
|
|
125
|
-
|
|
113
|
+
const unsubscribe = reactiveIndex.subscribeOnKeys(
|
|
114
|
+
stableKeys,
|
|
126
115
|
updateSnapshot
|
|
127
116
|
);
|
|
128
117
|
return () => {
|
|
129
|
-
|
|
130
|
-
prevKeys,
|
|
131
|
-
updateSnapshot
|
|
132
|
-
);
|
|
118
|
+
unsubscribe();
|
|
133
119
|
};
|
|
134
120
|
};
|
|
135
|
-
}, [
|
|
121
|
+
}, [reactiveIndex, stableKeys]);
|
|
136
122
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
137
123
|
return () => {
|
|
138
124
|
return snapshotValueRef.current;
|
|
@@ -160,18 +146,15 @@ var useSelectPksByIndexKeyArrayBased = (reactiveIndex, key) => {
|
|
|
160
146
|
snapshotValueRef.current = reactiveIndex.getPksByKey(prevKey);
|
|
161
147
|
onStoreChange();
|
|
162
148
|
};
|
|
163
|
-
reactiveIndex.
|
|
149
|
+
const unsubscribe = reactiveIndex.subscribeOnKey(
|
|
164
150
|
prevKey,
|
|
165
151
|
updateSnapshot
|
|
166
152
|
);
|
|
167
153
|
return () => {
|
|
168
|
-
|
|
169
|
-
prevKey,
|
|
170
|
-
updateSnapshot
|
|
171
|
-
);
|
|
154
|
+
unsubscribe();
|
|
172
155
|
};
|
|
173
156
|
};
|
|
174
|
-
}, [key, reactiveIndex
|
|
157
|
+
}, [key, reactiveIndex]);
|
|
175
158
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
176
159
|
return () => {
|
|
177
160
|
return snapshotValueRef.current;
|
|
@@ -187,18 +170,9 @@ var useSelectEntityByPk = (reactiveCollection, pk) => {
|
|
|
187
170
|
);
|
|
188
171
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
189
172
|
return (onStoreChange) => {
|
|
190
|
-
reactiveCollection.
|
|
191
|
-
pk,
|
|
192
|
-
onStoreChange
|
|
193
|
-
);
|
|
194
|
-
return () => {
|
|
195
|
-
reactiveCollection.updateEventEmitter.unsubscribeFromKey(
|
|
196
|
-
pk,
|
|
197
|
-
onStoreChange
|
|
198
|
-
);
|
|
199
|
-
};
|
|
173
|
+
return reactiveCollection.subscribeOnKey(pk, onStoreChange);
|
|
200
174
|
};
|
|
201
|
-
}, [pk, reactiveCollection
|
|
175
|
+
}, [pk, reactiveCollection]);
|
|
202
176
|
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
203
177
|
return snapshot;
|
|
204
178
|
};
|
|
@@ -209,18 +183,9 @@ var useSelectValueByObjectKey = (reactiveObject, key) => {
|
|
|
209
183
|
);
|
|
210
184
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
211
185
|
return (onStoreChange) => {
|
|
212
|
-
reactiveObject.
|
|
213
|
-
key,
|
|
214
|
-
onStoreChange
|
|
215
|
-
);
|
|
216
|
-
return () => {
|
|
217
|
-
reactiveObject.updateEventEmitter.unsubscribeFromKey(
|
|
218
|
-
key,
|
|
219
|
-
onStoreChange
|
|
220
|
-
);
|
|
221
|
-
};
|
|
186
|
+
return reactiveObject.subscribeOnKey(key, onStoreChange);
|
|
222
187
|
};
|
|
223
|
-
}, [key, reactiveObject
|
|
188
|
+
}, [key, reactiveObject]);
|
|
224
189
|
const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
225
190
|
return snapshot;
|
|
226
191
|
};
|
|
@@ -230,33 +195,26 @@ var useSelectValuesByObjectKeys = (reactiveObject, keys) => {
|
|
|
230
195
|
if (!keysAreEqual) {
|
|
231
196
|
prevKeysRef.current = keys;
|
|
232
197
|
}
|
|
198
|
+
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
233
199
|
const snapshotRef = (0, import_react.useRef)();
|
|
234
200
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
235
|
-
snapshotRef.current =
|
|
201
|
+
snapshotRef.current = stableKeys.map((key) => reactiveObject.get(key));
|
|
236
202
|
return (onStoreChange) => {
|
|
237
|
-
const prevKeys = prevKeysRef.current;
|
|
238
|
-
if (!prevKeys) {
|
|
239
|
-
return () => {
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
203
|
const updateSnapshot = () => {
|
|
243
|
-
snapshotRef.current =
|
|
204
|
+
snapshotRef.current = stableKeys.map(
|
|
244
205
|
(key) => reactiveObject.get(key)
|
|
245
206
|
);
|
|
246
207
|
onStoreChange();
|
|
247
208
|
};
|
|
248
|
-
reactiveObject.
|
|
249
|
-
|
|
209
|
+
const unsubscribe = reactiveObject.subscribeOnKeys(
|
|
210
|
+
stableKeys,
|
|
250
211
|
updateSnapshot
|
|
251
212
|
);
|
|
252
213
|
return () => {
|
|
253
|
-
|
|
254
|
-
prevKeys,
|
|
255
|
-
updateSnapshot
|
|
256
|
-
);
|
|
214
|
+
unsubscribe();
|
|
257
215
|
};
|
|
258
216
|
};
|
|
259
|
-
}, [
|
|
217
|
+
}, [reactiveObject, stableKeys]);
|
|
260
218
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
261
219
|
return () => {
|
|
262
220
|
return snapshotRef.current;
|
|
@@ -279,33 +237,28 @@ var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
|
279
237
|
if (!pksAreEqual) {
|
|
280
238
|
prevPksRef.current = pks;
|
|
281
239
|
}
|
|
240
|
+
const stablePks = pksAreEqual ? prevPksRef.current ?? pks : pks;
|
|
282
241
|
const snapshotRef = (0, import_react.useRef)();
|
|
283
242
|
const subscribe = (0, import_react.useMemo)(() => {
|
|
284
|
-
snapshotRef.current =
|
|
243
|
+
snapshotRef.current = stablePks.map(
|
|
244
|
+
(pk) => reactiveCollection.getOneByPk(pk)
|
|
245
|
+
);
|
|
285
246
|
return (onStoreChange) => {
|
|
286
|
-
const prevPks = prevPksRef.current;
|
|
287
|
-
if (!prevPks) {
|
|
288
|
-
return () => {
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
247
|
const updateSnapshot = () => {
|
|
292
|
-
snapshotRef.current =
|
|
248
|
+
snapshotRef.current = stablePks.map(
|
|
293
249
|
(pk) => reactiveCollection.getOneByPk(pk)
|
|
294
250
|
);
|
|
295
251
|
onStoreChange();
|
|
296
252
|
};
|
|
297
|
-
reactiveCollection.
|
|
298
|
-
|
|
253
|
+
const unsubscribe = reactiveCollection.subscribeOnKeys(
|
|
254
|
+
stablePks,
|
|
299
255
|
updateSnapshot
|
|
300
256
|
);
|
|
301
257
|
return () => {
|
|
302
|
-
|
|
303
|
-
prevPks,
|
|
304
|
-
updateSnapshot
|
|
305
|
-
);
|
|
258
|
+
unsubscribe();
|
|
306
259
|
};
|
|
307
260
|
};
|
|
308
|
-
}, [
|
|
261
|
+
}, [reactiveCollection, stablePks]);
|
|
309
262
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
310
263
|
return () => {
|
|
311
264
|
return snapshotRef.current;
|
|
@@ -315,60 +268,196 @@ var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
|
315
268
|
return snapshot;
|
|
316
269
|
};
|
|
317
270
|
var useSelectEntitiesByIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
() =>
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
271
|
+
const snapshotRef = (0, import_react.useRef)();
|
|
272
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
273
|
+
const readSnapshot = () => Array.from(
|
|
274
|
+
reactiveIndex.getPksByKey(key),
|
|
275
|
+
(pk) => reactiveCollection.getOneByPk(pk)
|
|
276
|
+
);
|
|
277
|
+
const readPks = () => Array.from(reactiveIndex.getPksByKey(key));
|
|
278
|
+
snapshotRef.current = readSnapshot();
|
|
279
|
+
return (onStoreChange) => {
|
|
280
|
+
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
281
|
+
snapshotRef.current = readSnapshot();
|
|
282
|
+
onStoreChange();
|
|
283
|
+
});
|
|
284
|
+
const resubscribeCollection = () => {
|
|
285
|
+
unsubscribeFromCollection();
|
|
286
|
+
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
287
|
+
readPks(),
|
|
288
|
+
() => {
|
|
289
|
+
snapshotRef.current = readSnapshot();
|
|
290
|
+
onStoreChange();
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
|
|
295
|
+
resubscribeCollection();
|
|
296
|
+
snapshotRef.current = readSnapshot();
|
|
297
|
+
onStoreChange();
|
|
298
|
+
});
|
|
299
|
+
return () => {
|
|
300
|
+
unsubscribeFromIndex();
|
|
301
|
+
unsubscribeFromCollection();
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
}, [key, reactiveCollection, reactiveIndex]);
|
|
305
|
+
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
|
|
306
|
+
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
324
307
|
};
|
|
325
308
|
var useSelectEntitiesByIndexKeysSetBased = (reactiveCollection, reactiveIndex, keys) => {
|
|
326
|
-
const
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
309
|
+
const prevKeysRef = (0, import_react.useRef)();
|
|
310
|
+
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
311
|
+
if (!keysAreEqual) {
|
|
312
|
+
prevKeysRef.current = keys;
|
|
313
|
+
}
|
|
314
|
+
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
315
|
+
const snapshotRef = (0, import_react.useRef)();
|
|
316
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
317
|
+
const readPks = () => stableKeys.flatMap(
|
|
318
|
+
(key) => Array.from(reactiveIndex.getPksByKey(key))
|
|
319
|
+
);
|
|
320
|
+
const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
|
|
321
|
+
snapshotRef.current = readSnapshot();
|
|
322
|
+
return (onStoreChange) => {
|
|
323
|
+
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
324
|
+
snapshotRef.current = readSnapshot();
|
|
325
|
+
onStoreChange();
|
|
326
|
+
});
|
|
327
|
+
const resubscribeCollection = () => {
|
|
328
|
+
unsubscribeFromCollection();
|
|
329
|
+
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
330
|
+
readPks(),
|
|
331
|
+
() => {
|
|
332
|
+
snapshotRef.current = readSnapshot();
|
|
333
|
+
onStoreChange();
|
|
334
|
+
}
|
|
335
|
+
);
|
|
336
|
+
};
|
|
337
|
+
const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
|
|
338
|
+
stableKeys,
|
|
339
|
+
() => {
|
|
340
|
+
resubscribeCollection();
|
|
341
|
+
snapshotRef.current = readSnapshot();
|
|
342
|
+
onStoreChange();
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
return () => {
|
|
346
|
+
unsubscribeFromIndex();
|
|
347
|
+
unsubscribeFromCollection();
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
}, [reactiveCollection, reactiveIndex, stableKeys]);
|
|
351
|
+
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
|
|
352
|
+
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
332
353
|
};
|
|
333
354
|
var useSelectEntitiesByIndexKeyArrayBased = (reactiveCollection, reactiveIndex, key) => {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
reactiveCollection
|
|
337
|
-
|
|
338
|
-
|
|
355
|
+
const snapshotRef = (0, import_react.useRef)();
|
|
356
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
357
|
+
const readSnapshot = () => reactiveIndex.getPksByKey(key).map((pk) => reactiveCollection.getOneByPk(pk));
|
|
358
|
+
const readPks = () => reactiveIndex.getPksByKey(key);
|
|
359
|
+
snapshotRef.current = readSnapshot();
|
|
360
|
+
return (onStoreChange) => {
|
|
361
|
+
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
362
|
+
snapshotRef.current = readSnapshot();
|
|
363
|
+
onStoreChange();
|
|
364
|
+
});
|
|
365
|
+
const resubscribeCollection = () => {
|
|
366
|
+
unsubscribeFromCollection();
|
|
367
|
+
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
368
|
+
readPks(),
|
|
369
|
+
() => {
|
|
370
|
+
snapshotRef.current = readSnapshot();
|
|
371
|
+
onStoreChange();
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
};
|
|
375
|
+
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
|
|
376
|
+
resubscribeCollection();
|
|
377
|
+
snapshotRef.current = readSnapshot();
|
|
378
|
+
onStoreChange();
|
|
379
|
+
});
|
|
380
|
+
return () => {
|
|
381
|
+
unsubscribeFromIndex();
|
|
382
|
+
unsubscribeFromCollection();
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
}, [key, reactiveCollection, reactiveIndex]);
|
|
386
|
+
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
|
|
387
|
+
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
339
388
|
};
|
|
340
389
|
var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex, keys) => {
|
|
341
|
-
const
|
|
342
|
-
|
|
390
|
+
const prevKeysRef = (0, import_react.useRef)();
|
|
391
|
+
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
392
|
+
if (!keysAreEqual) {
|
|
393
|
+
prevKeysRef.current = keys;
|
|
394
|
+
}
|
|
395
|
+
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
396
|
+
const snapshotRef = (0, import_react.useRef)();
|
|
397
|
+
const subscribe = (0, import_react.useMemo)(() => {
|
|
398
|
+
const readPks = () => stableKeys.flatMap((key) => reactiveIndex.getPksByKey(key));
|
|
399
|
+
const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
|
|
400
|
+
snapshotRef.current = readSnapshot();
|
|
401
|
+
return (onStoreChange) => {
|
|
402
|
+
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
403
|
+
snapshotRef.current = readSnapshot();
|
|
404
|
+
onStoreChange();
|
|
405
|
+
});
|
|
406
|
+
const resubscribeCollection = () => {
|
|
407
|
+
unsubscribeFromCollection();
|
|
408
|
+
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
409
|
+
readPks(),
|
|
410
|
+
() => {
|
|
411
|
+
snapshotRef.current = readSnapshot();
|
|
412
|
+
onStoreChange();
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
};
|
|
416
|
+
const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
|
|
417
|
+
stableKeys,
|
|
418
|
+
() => {
|
|
419
|
+
resubscribeCollection();
|
|
420
|
+
snapshotRef.current = readSnapshot();
|
|
421
|
+
onStoreChange();
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
return () => {
|
|
425
|
+
unsubscribeFromIndex();
|
|
426
|
+
unsubscribeFromCollection();
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
}, [reactiveCollection, reactiveIndex, stableKeys]);
|
|
430
|
+
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
|
|
431
|
+
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
343
432
|
};
|
|
344
433
|
|
|
345
434
|
// src/context/index.tsx
|
|
346
435
|
var import_react3 = require("react");
|
|
347
436
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
348
|
-
var
|
|
437
|
+
var OIMCollectionsContext = (0, import_react3.createContext)(
|
|
349
438
|
{}
|
|
350
439
|
);
|
|
351
440
|
function createOIMCollectionsContext() {
|
|
352
441
|
return (0, import_react3.createContext)({});
|
|
353
442
|
}
|
|
354
|
-
function
|
|
355
|
-
const ContextToUse = context ||
|
|
443
|
+
function OIMCollectionsProvider({ collections, children, context }) {
|
|
444
|
+
const ContextToUse = context || OIMCollectionsContext;
|
|
356
445
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextToUse.Provider, { value: collections, children });
|
|
357
446
|
}
|
|
358
447
|
function useOIMCollectionsContext(context) {
|
|
359
|
-
const contextToUse = context ||
|
|
448
|
+
const contextToUse = context || OIMCollectionsContext;
|
|
360
449
|
const collections = (0, import_react3.useContext)(contextToUse);
|
|
361
450
|
if (!collections || Object.keys(collections).length === 0) {
|
|
362
451
|
throw new Error(
|
|
363
|
-
"useOIMCollectionsContext must be used within an
|
|
452
|
+
"useOIMCollectionsContext must be used within an OIMCollectionsProvider"
|
|
364
453
|
);
|
|
365
454
|
}
|
|
366
455
|
return collections;
|
|
367
456
|
}
|
|
368
457
|
// Annotate the CommonJS export names for ESM import in node:
|
|
369
458
|
0 && (module.exports = {
|
|
370
|
-
|
|
371
|
-
|
|
459
|
+
OIMCollectionsContext,
|
|
460
|
+
OIMCollectionsProvider,
|
|
372
461
|
createOIMCollectionsContext,
|
|
373
462
|
useOIMCollectionsContext,
|
|
374
463
|
useSelectEntitiesByIndexKeyArrayBased,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMReactiveObject
|
|
1
|
+
import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMReactiveObject } 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
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
|
|
7
|
+
declare const useSelectPksByIndexKeySetBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => Set<TPk> | undefined;
|
|
8
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
9
|
declare const useSelectPksByIndexKeyArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => TPk[] | undefined;
|
|
10
10
|
declare const useSelectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
|
|
@@ -16,16 +16,16 @@ declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk
|
|
|
16
16
|
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;
|
|
17
17
|
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;
|
|
18
18
|
|
|
19
|
-
type CollectionsDictionary = Record<string,
|
|
19
|
+
type CollectionsDictionary = Record<string, OIMReactiveCollection<any, any>>;
|
|
20
20
|
type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
|
|
21
|
-
declare const
|
|
21
|
+
declare const OIMCollectionsContext: React.Context<CollectionsDictionary>;
|
|
22
22
|
declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
|
|
23
|
-
interface
|
|
23
|
+
interface OIMCollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
|
|
24
24
|
collections: T;
|
|
25
25
|
children: ReactNode;
|
|
26
26
|
context?: React.Context<OIMContextValue<T>>;
|
|
27
27
|
}
|
|
28
|
-
declare function
|
|
28
|
+
declare function OIMCollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMCollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
|
|
29
29
|
declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
|
|
30
30
|
|
|
31
|
-
export { type CollectionsDictionary,
|
|
31
|
+
export { type CollectionsDictionary, OIMCollectionsContext, OIMCollectionsProvider, type OIMCollectionsProviderProps, type OIMContextValue, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased, useSelectValueByObjectKey, useSelectValuesByObjectKeys };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMReactiveObject
|
|
1
|
+
import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMReactiveObject } 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
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
|
|
7
|
+
declare const useSelectPksByIndexKeySetBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => Set<TPk> | undefined;
|
|
8
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
9
|
declare const useSelectPksByIndexKeyArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => TPk[] | undefined;
|
|
10
10
|
declare const useSelectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
|
|
@@ -16,16 +16,16 @@ declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk
|
|
|
16
16
|
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;
|
|
17
17
|
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;
|
|
18
18
|
|
|
19
|
-
type CollectionsDictionary = Record<string,
|
|
19
|
+
type CollectionsDictionary = Record<string, OIMReactiveCollection<any, any>>;
|
|
20
20
|
type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
|
|
21
|
-
declare const
|
|
21
|
+
declare const OIMCollectionsContext: React.Context<CollectionsDictionary>;
|
|
22
22
|
declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
|
|
23
|
-
interface
|
|
23
|
+
interface OIMCollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
|
|
24
24
|
collections: T;
|
|
25
25
|
children: ReactNode;
|
|
26
26
|
context?: React.Context<OIMContextValue<T>>;
|
|
27
27
|
}
|
|
28
|
-
declare function
|
|
28
|
+
declare function OIMCollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMCollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
|
|
29
29
|
declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
|
|
30
30
|
|
|
31
|
-
export { type CollectionsDictionary,
|
|
31
|
+
export { type CollectionsDictionary, OIMCollectionsContext, OIMCollectionsProvider, type OIMCollectionsProviderProps, type OIMContextValue, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased, useSelectValueByObjectKey, useSelectValuesByObjectKeys };
|