@oimdb/react 2.2.0 → 3.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 +266 -133
- package/dist/index.cjs +340 -727
- package/dist/index.d.cts +53 -46
- package/dist/index.d.ts +53 -46
- package/dist/index.js +326 -699
- package/llms.txt +4156 -0
- package/package.json +46 -36
package/dist/index.cjs
CHANGED
|
@@ -20,760 +20,373 @@ 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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
useSelectPksByCompositeIndexKeyArrayBased: () => useSelectPksByCompositeIndexKeyArrayBased,
|
|
39
|
-
useSelectPksByCompositeIndexKeySetBased: () => useSelectPksByCompositeIndexKeySetBased,
|
|
40
|
-
useSelectPksByGlobalIndexArrayBased: () => useSelectPksByGlobalIndexArrayBased,
|
|
41
|
-
useSelectPksByGlobalIndexArrayBasedSignal: () => useSelectPksByGlobalIndexArrayBasedSignal,
|
|
42
|
-
useSelectPksByGlobalIndexSetBased: () => useSelectPksByGlobalIndexSetBased,
|
|
43
|
-
useSelectPksByGlobalIndexSetBasedSignal: () => useSelectPksByGlobalIndexSetBasedSignal,
|
|
44
|
-
useSelectPksByIndexKeyArrayBased: () => useSelectPksByIndexKeyArrayBased,
|
|
45
|
-
useSelectPksByIndexKeyArrayBasedSignal: () => useSelectPksByIndexKeyArrayBasedSignal,
|
|
46
|
-
useSelectPksByIndexKeySetBased: () => useSelectPksByIndexKeySetBased,
|
|
47
|
-
useSelectPksByIndexKeySetBasedSignal: () => useSelectPksByIndexKeySetBasedSignal,
|
|
48
|
-
useSelectPksByIndexKeysArrayBased: () => useSelectPksByIndexKeysArrayBased,
|
|
49
|
-
useSelectPksByIndexKeysSetBased: () => useSelectPksByIndexKeysSetBased,
|
|
50
|
-
useSelectValueByObjectKey: () => useSelectValueByObjectKey,
|
|
51
|
-
useSelectValuesByObjectKeys: () => useSelectValuesByObjectKeys
|
|
23
|
+
OIMDBContext: () => OIMDBContext,
|
|
24
|
+
OIMDBProvider: () => OIMDBProvider,
|
|
25
|
+
useOIMBucketSlots: () => useOIMBucketSlots,
|
|
26
|
+
useOIMBucketSlotsByKey: () => useOIMBucketSlotsByKey,
|
|
27
|
+
useOIMComputedCollection: () => useOIMComputedCollection,
|
|
28
|
+
useOIMComputedValue: () => useOIMComputedValue,
|
|
29
|
+
useOIMComputedValueByKey: () => useOIMComputedValueByKey,
|
|
30
|
+
useOIMDB: () => useOIMDB,
|
|
31
|
+
useOIMEntity: () => useOIMEntity,
|
|
32
|
+
useOIMField: () => useOIMField,
|
|
33
|
+
useOIMSingleBucketSlots: () => useOIMSingleBucketSlots,
|
|
34
|
+
useOIMSingleComputedValue: () => useOIMSingleComputedValue,
|
|
35
|
+
useOIMSingleEntity: () => useOIMSingleEntity,
|
|
36
|
+
useOIMSlotsByKeys: () => useOIMSlotsByKeys,
|
|
37
|
+
useOIMValue: () => useOIMValue
|
|
52
38
|
});
|
|
53
39
|
module.exports = __toCommonJS(index_exports);
|
|
54
40
|
|
|
55
|
-
// src/
|
|
56
|
-
var import_react3 = require("react");
|
|
57
|
-
var import_react4 = require("react");
|
|
58
|
-
|
|
59
|
-
// src/hooks/global.ts
|
|
41
|
+
// src/OIMDBContext.ts
|
|
60
42
|
var import_react = require("react");
|
|
61
|
-
var
|
|
62
|
-
const snapshotValueRef = (0, import_react.useRef)();
|
|
63
|
-
const subscribe = (0, import_react.useMemo)(() => {
|
|
64
|
-
snapshotValueRef.current = reactiveIndex.getPks();
|
|
65
|
-
return (onStoreChange) => {
|
|
66
|
-
return reactiveIndex.subscribe(() => {
|
|
67
|
-
snapshotValueRef.current = reactiveIndex.getPks();
|
|
68
|
-
onStoreChange();
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
}, [reactiveIndex]);
|
|
72
|
-
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
|
|
73
|
-
return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
74
|
-
};
|
|
75
|
-
var useSelectPksByGlobalIndexSetBased = (reactiveIndex) => {
|
|
76
|
-
const snapshotValueRef = (0, import_react.useRef)();
|
|
77
|
-
const subscribe = (0, import_react.useMemo)(() => {
|
|
78
|
-
snapshotValueRef.current = reactiveIndex.getPks();
|
|
79
|
-
return (onStoreChange) => {
|
|
80
|
-
return reactiveIndex.subscribe(() => {
|
|
81
|
-
snapshotValueRef.current = reactiveIndex.getPks();
|
|
82
|
-
onStoreChange();
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
}, [reactiveIndex]);
|
|
86
|
-
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
|
|
87
|
-
return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
88
|
-
};
|
|
89
|
-
var useSelectEntitiesByGlobalIndexArrayBased = (reactiveCollection, reactiveIndex) => {
|
|
90
|
-
const snapshotRef = (0, import_react.useRef)();
|
|
91
|
-
const subscribe = (0, import_react.useMemo)(() => {
|
|
92
|
-
const readPks = () => reactiveIndex.getPks();
|
|
93
|
-
const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
|
|
94
|
-
snapshotRef.current = readSnapshot();
|
|
95
|
-
return (onStoreChange) => {
|
|
96
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
97
|
-
readPks(),
|
|
98
|
-
() => {
|
|
99
|
-
snapshotRef.current = readSnapshot();
|
|
100
|
-
onStoreChange();
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
const resubscribeCollection = () => {
|
|
104
|
-
unsubscribeFromCollection();
|
|
105
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
106
|
-
readPks(),
|
|
107
|
-
() => {
|
|
108
|
-
snapshotRef.current = readSnapshot();
|
|
109
|
-
onStoreChange();
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
const unsubscribeFromIndex = reactiveIndex.subscribe(() => {
|
|
114
|
-
resubscribeCollection();
|
|
115
|
-
snapshotRef.current = readSnapshot();
|
|
116
|
-
onStoreChange();
|
|
117
|
-
});
|
|
118
|
-
return () => {
|
|
119
|
-
unsubscribeFromIndex();
|
|
120
|
-
unsubscribeFromCollection();
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
}, [reactiveCollection, reactiveIndex]);
|
|
124
|
-
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
|
|
125
|
-
return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
126
|
-
};
|
|
127
|
-
var useSelectEntitiesByGlobalIndexSetBased = (reactiveCollection, reactiveIndex) => {
|
|
128
|
-
const snapshotRef = (0, import_react.useRef)();
|
|
129
|
-
const subscribe = (0, import_react.useMemo)(() => {
|
|
130
|
-
const readPks = () => Array.from(reactiveIndex.getPks());
|
|
131
|
-
const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
|
|
132
|
-
snapshotRef.current = readSnapshot();
|
|
133
|
-
return (onStoreChange) => {
|
|
134
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
135
|
-
readPks(),
|
|
136
|
-
() => {
|
|
137
|
-
snapshotRef.current = readSnapshot();
|
|
138
|
-
onStoreChange();
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
const resubscribeCollection = () => {
|
|
142
|
-
unsubscribeFromCollection();
|
|
143
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
144
|
-
readPks(),
|
|
145
|
-
() => {
|
|
146
|
-
snapshotRef.current = readSnapshot();
|
|
147
|
-
onStoreChange();
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
const unsubscribeFromIndex = reactiveIndex.subscribe(() => {
|
|
152
|
-
resubscribeCollection();
|
|
153
|
-
snapshotRef.current = readSnapshot();
|
|
154
|
-
onStoreChange();
|
|
155
|
-
});
|
|
156
|
-
return () => {
|
|
157
|
-
unsubscribeFromIndex();
|
|
158
|
-
unsubscribeFromCollection();
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
}, [reactiveCollection, reactiveIndex]);
|
|
162
|
-
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
|
|
163
|
-
return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
164
|
-
};
|
|
43
|
+
var OIMDBContext = (0, import_react.createContext)(void 0);
|
|
165
44
|
|
|
166
|
-
// src/
|
|
167
|
-
var
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const [, force] = (0, import_react2.useReducer)((c) => c + 1 | 0, 0);
|
|
171
|
-
return force;
|
|
45
|
+
// src/OIMDBProvider.tsx
|
|
46
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
function OIMDBProvider({ db, children }) {
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OIMDBContext.Provider, { value: db, children });
|
|
172
49
|
}
|
|
173
|
-
var useSelectEntityByPkSignal = (reactiveCollection, pk) => {
|
|
174
|
-
const force = useForceUpdate();
|
|
175
|
-
useIsomorphicLayoutEffect(
|
|
176
|
-
() => reactiveCollection.subscribeOnKey(pk, force),
|
|
177
|
-
[reactiveCollection, pk]
|
|
178
|
-
);
|
|
179
|
-
return reactiveCollection.getOneByPk(pk);
|
|
180
|
-
};
|
|
181
|
-
var useSelectPksByIndexKeyArrayBasedSignal = (reactiveIndex, key) => {
|
|
182
|
-
const force = useForceUpdate();
|
|
183
|
-
useIsomorphicLayoutEffect(
|
|
184
|
-
() => reactiveIndex.subscribeOnKey(key, force),
|
|
185
|
-
[reactiveIndex, key]
|
|
186
|
-
);
|
|
187
|
-
return reactiveIndex.getPksByKey(key);
|
|
188
|
-
};
|
|
189
|
-
var useSelectPksByIndexKeySetBasedSignal = (reactiveIndex, key) => {
|
|
190
|
-
const force = useForceUpdate();
|
|
191
|
-
useIsomorphicLayoutEffect(
|
|
192
|
-
() => reactiveIndex.subscribeOnKey(key, force),
|
|
193
|
-
[reactiveIndex, key]
|
|
194
|
-
);
|
|
195
|
-
return reactiveIndex.getPksByKey(key);
|
|
196
|
-
};
|
|
197
|
-
var useSelectPksByGlobalIndexArrayBasedSignal = (reactiveIndex) => {
|
|
198
|
-
const force = useForceUpdate();
|
|
199
|
-
useIsomorphicLayoutEffect(
|
|
200
|
-
() => reactiveIndex.subscribe(force),
|
|
201
|
-
[reactiveIndex]
|
|
202
|
-
);
|
|
203
|
-
return reactiveIndex.getPks();
|
|
204
|
-
};
|
|
205
|
-
var useSelectPksByGlobalIndexSetBasedSignal = (reactiveIndex) => {
|
|
206
|
-
const force = useForceUpdate();
|
|
207
|
-
useIsomorphicLayoutEffect(
|
|
208
|
-
() => reactiveIndex.subscribe(force),
|
|
209
|
-
[reactiveIndex]
|
|
210
|
-
);
|
|
211
|
-
return reactiveIndex.getPks();
|
|
212
|
-
};
|
|
213
50
|
|
|
214
|
-
// src/
|
|
215
|
-
var
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
51
|
+
// src/useOIMDB.ts
|
|
52
|
+
var import_react2 = require("react");
|
|
53
|
+
function useOIMDB() {
|
|
54
|
+
const db = (0, import_react2.useContext)(OIMDBContext);
|
|
55
|
+
if (db === void 0) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"useOIMDB: no <OIMDBProvider db={...}> above this component. The hooks that build a computed for the component take the database from it."
|
|
58
|
+
);
|
|
221
59
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return () => {
|
|
236
|
-
unsubscribe();
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
}, [reactiveIndex, stableKeys]);
|
|
240
|
-
const getSnapshot = (0, import_react3.useMemo)(() => {
|
|
241
|
-
return () => {
|
|
242
|
-
return snapshotValueRef.current;
|
|
243
|
-
};
|
|
244
|
-
}, []);
|
|
245
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
246
|
-
return snapshot;
|
|
247
|
-
};
|
|
248
|
-
var useSelectPksByIndexKeySetBased = (reactiveIndex, key) => {
|
|
249
|
-
const snapshotValueRef = (0, import_react3.useRef)();
|
|
250
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
251
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
252
|
-
return (onStoreChange) => {
|
|
253
|
-
const updateSnapshot = () => {
|
|
254
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
255
|
-
onStoreChange();
|
|
256
|
-
};
|
|
257
|
-
return reactiveIndex.subscribeOnKey(key, updateSnapshot);
|
|
258
|
-
};
|
|
259
|
-
}, [key, reactiveIndex]);
|
|
260
|
-
const getSnapshot = (0, import_react3.useMemo)(() => {
|
|
261
|
-
return () => {
|
|
262
|
-
return snapshotValueRef.current;
|
|
263
|
-
};
|
|
264
|
-
}, []);
|
|
265
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
266
|
-
return snapshot;
|
|
267
|
-
};
|
|
268
|
-
var useSelectPksByIndexKeysArrayBased = (reactiveIndex, keys) => {
|
|
269
|
-
const prevKeysRef = (0, import_react3.useRef)();
|
|
270
|
-
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
271
|
-
if (!keysAreEqual) {
|
|
272
|
-
prevKeysRef.current = keys;
|
|
60
|
+
return db;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/useOIMValue.ts
|
|
64
|
+
var import_react4 = require("react");
|
|
65
|
+
var import_core2 = require("@oimdb/core");
|
|
66
|
+
|
|
67
|
+
// src/OIMSnapshotVersion.ts
|
|
68
|
+
var import_core = require("@oimdb/core");
|
|
69
|
+
var OIMSnapshotVersion = class {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.version = 0;
|
|
72
|
+
this.getVersion = () => this.version;
|
|
273
73
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
snapshotValueRef.current = stableKeys.map((key) => reactiveIndex.getPksByKey(key)).flat();
|
|
281
|
-
onStoreChange();
|
|
282
|
-
};
|
|
283
|
-
const unsubscribe = reactiveIndex.subscribeOnKeys(
|
|
284
|
-
stableKeys,
|
|
285
|
-
updateSnapshot
|
|
286
|
-
);
|
|
287
|
-
return () => {
|
|
288
|
-
unsubscribe();
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
}, [reactiveIndex, stableKeys]);
|
|
292
|
-
const getSnapshot = (0, import_react3.useMemo)(() => {
|
|
293
|
-
return () => {
|
|
294
|
-
return snapshotValueRef.current;
|
|
295
|
-
};
|
|
296
|
-
}, []);
|
|
297
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
298
|
-
return snapshot;
|
|
299
|
-
};
|
|
300
|
-
var useSelectPksByIndexKeyArrayBased = (reactiveIndex, key) => {
|
|
301
|
-
const prevKeyRef = (0, import_react3.useRef)();
|
|
302
|
-
const keyAreEqual = prevKeyRef.current === key;
|
|
303
|
-
if (!keyAreEqual) {
|
|
304
|
-
prevKeyRef.current = key;
|
|
74
|
+
subscribeEffect(channelMap, sourceSlots, sourceComputeds, onStoreChange) {
|
|
75
|
+
this.version++;
|
|
76
|
+
return import_core.OIMEffectService.INSTANCE.subscribeEffect(channelMap, sourceSlots, sourceComputeds, () => {
|
|
77
|
+
this.version++;
|
|
78
|
+
onStoreChange();
|
|
79
|
+
});
|
|
305
80
|
}
|
|
306
|
-
const snapshotValueRef = (0, import_react3.useRef)();
|
|
307
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
308
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
309
|
-
return (onStoreChange) => {
|
|
310
|
-
const prevKey = prevKeyRef.current;
|
|
311
|
-
if (!prevKey) {
|
|
312
|
-
return () => {
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
const updateSnapshot = () => {
|
|
316
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(prevKey);
|
|
317
|
-
onStoreChange();
|
|
318
|
-
};
|
|
319
|
-
const unsubscribe = reactiveIndex.subscribeOnKey(
|
|
320
|
-
prevKey,
|
|
321
|
-
updateSnapshot
|
|
322
|
-
);
|
|
323
|
-
return () => {
|
|
324
|
-
unsubscribe();
|
|
325
|
-
};
|
|
326
|
-
};
|
|
327
|
-
}, [key, reactiveIndex]);
|
|
328
|
-
const getSnapshot = (0, import_react3.useMemo)(() => {
|
|
329
|
-
return () => {
|
|
330
|
-
return snapshotValueRef.current;
|
|
331
|
-
};
|
|
332
|
-
}, []);
|
|
333
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
334
|
-
return snapshot;
|
|
335
81
|
};
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
82
|
+
|
|
83
|
+
// src/useOIMSnapshotVersion.ts
|
|
84
|
+
var import_react3 = require("react");
|
|
85
|
+
function useOIMSnapshotVersion(snapshotVersion, subscribe) {
|
|
86
|
+
return (0, import_react3.useSyncExternalStore)(subscribe, snapshotVersion.getVersion, snapshotVersion.getVersion);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/useOIMValue.ts
|
|
90
|
+
function useOIMValue(binding) {
|
|
91
|
+
const db = useOIMDB();
|
|
92
|
+
const sourceComputeds = binding.sourceComputeds ?? import_core2.OIM_FROZEN_EMPTY_SLOTS;
|
|
93
|
+
const store = (0, import_react4.useMemo)(() => {
|
|
94
|
+
const snapshotVersion = new OIMSnapshotVersion();
|
|
95
|
+
return {
|
|
96
|
+
snapshotVersion,
|
|
97
|
+
subscribe: (onStoreChange) => snapshotVersion.subscribeEffect(
|
|
98
|
+
db,
|
|
99
|
+
binding.sourceSlots ?? import_core2.OIM_FROZEN_EMPTY_SLOTS,
|
|
100
|
+
sourceComputeds,
|
|
101
|
+
onStoreChange
|
|
102
|
+
)
|
|
344
103
|
};
|
|
345
|
-
}, [
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
104
|
+
}, [db, binding, sourceComputeds]);
|
|
105
|
+
useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
|
|
106
|
+
(0, import_core2.oimRefreshSourceComputeds)(sourceComputeds);
|
|
107
|
+
return binding.derive();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/useOIMComputedValue.ts
|
|
111
|
+
var import_react5 = require("react");
|
|
112
|
+
function useOIMComputedValue(computedSlot) {
|
|
113
|
+
const binding = (0, import_react5.useMemo)(() => ({
|
|
114
|
+
sourceComputeds: [computedSlot],
|
|
115
|
+
derive: () => computedSlot.value
|
|
116
|
+
}), [computedSlot]);
|
|
117
|
+
return useOIMValue(binding);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/useOIMSlotByKey.ts
|
|
121
|
+
var import_react6 = require("react");
|
|
122
|
+
var import_core3 = require("@oimdb/core");
|
|
123
|
+
|
|
124
|
+
// src/oimAssertOneChannel.ts
|
|
125
|
+
function oimAssertOneChannel(channelMap, slot, door) {
|
|
126
|
+
const storeSlot = slot.storeSlot;
|
|
127
|
+
if (storeSlot === void 0 || storeSlot.channelSlot === channelMap.defaultChannelSlot) return;
|
|
128
|
+
throw new Error(
|
|
129
|
+
`${door}: the slot was filed on another OIMDB than the one <OIMDBProvider> was given, so a write would never wake this component. Build the services and their store slots on the one OIMDB the provider holds.`
|
|
353
130
|
);
|
|
354
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
355
|
-
return (onStoreChange) => {
|
|
356
|
-
return reactiveObject.subscribeOnKey(key, onStoreChange);
|
|
357
|
-
};
|
|
358
|
-
}, [key, reactiveObject]);
|
|
359
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
360
|
-
return snapshot;
|
|
361
|
-
};
|
|
362
|
-
var useSelectValuesByObjectKeys = (reactiveObject, keys) => {
|
|
363
|
-
const prevKeysRef = (0, import_react3.useRef)();
|
|
364
|
-
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
365
|
-
if (!keysAreEqual) {
|
|
366
|
-
prevKeysRef.current = keys;
|
|
367
|
-
}
|
|
368
|
-
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
369
|
-
const snapshotRef = (0, import_react3.useRef)();
|
|
370
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
371
|
-
snapshotRef.current = stableKeys.map((key) => reactiveObject.get(key));
|
|
372
|
-
return (onStoreChange) => {
|
|
373
|
-
const updateSnapshot = () => {
|
|
374
|
-
snapshotRef.current = stableKeys.map(
|
|
375
|
-
(key) => reactiveObject.get(key)
|
|
376
|
-
);
|
|
377
|
-
onStoreChange();
|
|
378
|
-
};
|
|
379
|
-
const unsubscribe = reactiveObject.subscribeOnKeys(
|
|
380
|
-
stableKeys,
|
|
381
|
-
updateSnapshot
|
|
382
|
-
);
|
|
383
|
-
return () => {
|
|
384
|
-
unsubscribe();
|
|
385
|
-
};
|
|
386
|
-
};
|
|
387
|
-
}, [reactiveObject, stableKeys]);
|
|
388
|
-
const getSnapshot = (0, import_react3.useMemo)(() => {
|
|
389
|
-
return () => {
|
|
390
|
-
return snapshotRef.current;
|
|
391
|
-
};
|
|
392
|
-
}, []);
|
|
393
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
394
|
-
return snapshot;
|
|
395
|
-
};
|
|
396
|
-
function arraysEqual(a, b) {
|
|
397
|
-
if (a === b) return true;
|
|
398
|
-
if (a.length !== b.length) return false;
|
|
399
|
-
for (let i = 0; i < a.length; i++) {
|
|
400
|
-
if (a[i] !== b[i]) return false;
|
|
401
|
-
}
|
|
402
|
-
return true;
|
|
403
131
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
return (onStoreChange) => {
|
|
417
|
-
const updateSnapshot = () => {
|
|
418
|
-
snapshotRef.current = stablePks.map(
|
|
419
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
420
|
-
);
|
|
421
|
-
onStoreChange();
|
|
422
|
-
};
|
|
423
|
-
const unsubscribe = reactiveCollection.subscribeOnKeys(
|
|
424
|
-
stablePks,
|
|
425
|
-
updateSnapshot
|
|
426
|
-
);
|
|
427
|
-
return () => {
|
|
428
|
-
unsubscribe();
|
|
429
|
-
};
|
|
430
|
-
};
|
|
431
|
-
}, [reactiveCollection, stablePks]);
|
|
432
|
-
const getSnapshot = (0, import_react3.useMemo)(() => {
|
|
433
|
-
return () => {
|
|
434
|
-
return snapshotRef.current;
|
|
435
|
-
};
|
|
436
|
-
}, []);
|
|
437
|
-
const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
438
|
-
return snapshot;
|
|
439
|
-
};
|
|
440
|
-
var useSelectEntitiesByIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
|
|
441
|
-
const snapshotRef = (0, import_react3.useRef)();
|
|
442
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
443
|
-
const readSnapshot = () => Array.from(
|
|
444
|
-
reactiveIndex.getPksByKey(key),
|
|
445
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
446
|
-
);
|
|
447
|
-
const readPks = () => Array.from(reactiveIndex.getPksByKey(key));
|
|
448
|
-
snapshotRef.current = readSnapshot();
|
|
449
|
-
return (onStoreChange) => {
|
|
450
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
451
|
-
snapshotRef.current = readSnapshot();
|
|
452
|
-
onStoreChange();
|
|
453
|
-
});
|
|
454
|
-
const resubscribeCollection = () => {
|
|
455
|
-
unsubscribeFromCollection();
|
|
456
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
457
|
-
readPks(),
|
|
458
|
-
() => {
|
|
459
|
-
snapshotRef.current = readSnapshot();
|
|
460
|
-
onStoreChange();
|
|
461
|
-
}
|
|
462
|
-
);
|
|
463
|
-
};
|
|
464
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
|
|
465
|
-
resubscribeCollection();
|
|
466
|
-
snapshotRef.current = readSnapshot();
|
|
467
|
-
onStoreChange();
|
|
468
|
-
});
|
|
469
|
-
return () => {
|
|
470
|
-
unsubscribeFromIndex();
|
|
471
|
-
unsubscribeFromCollection();
|
|
472
|
-
};
|
|
473
|
-
};
|
|
474
|
-
}, [key, reactiveCollection, reactiveIndex]);
|
|
475
|
-
const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
|
|
476
|
-
return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
477
|
-
};
|
|
478
|
-
var useSelectEntitiesByIndexKeysSetBased = (reactiveCollection, reactiveIndex, keys) => {
|
|
479
|
-
const prevKeysRef = (0, import_react3.useRef)();
|
|
480
|
-
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
481
|
-
if (!keysAreEqual) {
|
|
482
|
-
prevKeysRef.current = keys;
|
|
132
|
+
|
|
133
|
+
// src/useOIMSlotByKey.ts
|
|
134
|
+
var sourcesOfRootSlot = (rootSlot) => [[rootSlot], import_core3.OIM_FROZEN_EMPTY_SLOTS];
|
|
135
|
+
function useOIMSlotByKey(hookName, slotCollectionService, storeSlot, key, sourcesOfSlot = sourcesOfRootSlot) {
|
|
136
|
+
const db = useOIMDB();
|
|
137
|
+
const lastSeenKeyRef = (0, import_react6.useRef)(key);
|
|
138
|
+
const settledKeyRef = (0, import_react6.useRef)(key);
|
|
139
|
+
if (key !== lastSeenKeyRef.current) {
|
|
140
|
+
lastSeenKeyRef.current = key;
|
|
141
|
+
if (slotCollectionService.getSlotByKey(storeSlot, key) !== slotCollectionService.getSlotByKey(storeSlot, settledKeyRef.current)) {
|
|
142
|
+
settledKeyRef.current = key;
|
|
143
|
+
}
|
|
483
144
|
}
|
|
484
|
-
const
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
onStoreChange();
|
|
504
|
-
}
|
|
505
|
-
);
|
|
506
|
-
};
|
|
507
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
|
|
508
|
-
stableKeys,
|
|
509
|
-
() => {
|
|
510
|
-
resubscribeCollection();
|
|
511
|
-
snapshotRef.current = readSnapshot();
|
|
512
|
-
onStoreChange();
|
|
145
|
+
const settledKey = settledKeyRef.current;
|
|
146
|
+
const store = (0, import_react6.useMemo)(() => {
|
|
147
|
+
const snapshotVersion = new OIMSnapshotVersion();
|
|
148
|
+
let subscribedSlot = void 0;
|
|
149
|
+
return {
|
|
150
|
+
snapshotVersion,
|
|
151
|
+
subscribe: (onStoreChange) => {
|
|
152
|
+
const holdingSlot = slotCollectionService.holdSlotByKey(storeSlot, settledKey);
|
|
153
|
+
try {
|
|
154
|
+
oimAssertOneChannel(db, holdingSlot, hookName);
|
|
155
|
+
const [sourceSlots, sourceComputeds] = sourcesOfSlot(holdingSlot);
|
|
156
|
+
const disposeEffect = snapshotVersion.subscribeEffect(db, sourceSlots, sourceComputeds, onStoreChange);
|
|
157
|
+
subscribedSlot = holdingSlot;
|
|
158
|
+
return () => {
|
|
159
|
+
subscribedSlot = void 0;
|
|
160
|
+
disposeEffect();
|
|
161
|
+
};
|
|
162
|
+
} finally {
|
|
163
|
+
holdingSlot.owner.unholdSlot(holdingSlot);
|
|
513
164
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
unsubscribeFromIndex();
|
|
517
|
-
unsubscribeFromCollection();
|
|
518
|
-
};
|
|
519
|
-
};
|
|
520
|
-
}, [reactiveCollection, reactiveIndex, stableKeys]);
|
|
521
|
-
const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
|
|
522
|
-
return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
523
|
-
};
|
|
524
|
-
var useSelectEntitiesByIndexKeyArrayBased = (reactiveCollection, reactiveIndex, key) => {
|
|
525
|
-
const snapshotRef = (0, import_react3.useRef)();
|
|
526
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
527
|
-
const readSnapshot = () => reactiveIndex.getPksByKey(key).map((pk) => reactiveCollection.getOneByPk(pk));
|
|
528
|
-
const readPks = () => reactiveIndex.getPksByKey(key);
|
|
529
|
-
snapshotRef.current = readSnapshot();
|
|
530
|
-
return (onStoreChange) => {
|
|
531
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
532
|
-
snapshotRef.current = readSnapshot();
|
|
533
|
-
onStoreChange();
|
|
534
|
-
});
|
|
535
|
-
const resubscribeCollection = () => {
|
|
536
|
-
unsubscribeFromCollection();
|
|
537
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
538
|
-
readPks(),
|
|
539
|
-
() => {
|
|
540
|
-
snapshotRef.current = readSnapshot();
|
|
541
|
-
onStoreChange();
|
|
542
|
-
}
|
|
543
|
-
);
|
|
544
|
-
};
|
|
545
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
|
|
546
|
-
resubscribeCollection();
|
|
547
|
-
snapshotRef.current = readSnapshot();
|
|
548
|
-
onStoreChange();
|
|
549
|
-
});
|
|
550
|
-
return () => {
|
|
551
|
-
unsubscribeFromIndex();
|
|
552
|
-
unsubscribeFromCollection();
|
|
553
|
-
};
|
|
165
|
+
},
|
|
166
|
+
getSlot: () => subscribedSlot ?? slotCollectionService.getSlotByKey(storeSlot, settledKey)
|
|
554
167
|
};
|
|
555
|
-
}, [
|
|
556
|
-
|
|
557
|
-
return
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
() => {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
|
|
587
|
-
stableKeys,
|
|
588
|
-
() => {
|
|
589
|
-
resubscribeCollection();
|
|
590
|
-
snapshotRef.current = readSnapshot();
|
|
591
|
-
onStoreChange();
|
|
168
|
+
}, [hookName, db, slotCollectionService, storeSlot, settledKey, sourcesOfSlot]);
|
|
169
|
+
useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
|
|
170
|
+
return store.getSlot();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/useOIMEntity.ts
|
|
174
|
+
function useOIMEntity(entityCollectionService, entityStoreSlot, key) {
|
|
175
|
+
return useOIMSlotByKey("useOIMEntity", entityCollectionService, entityStoreSlot, key).entity;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/useOIMSingleSlot.ts
|
|
179
|
+
var import_react7 = require("react");
|
|
180
|
+
function useOIMSingleSlot(hookName, singleSlotService, singleSlotStoreSlot) {
|
|
181
|
+
const db = useOIMDB();
|
|
182
|
+
const store = (0, import_react7.useMemo)(() => {
|
|
183
|
+
const snapshotVersion = new OIMSnapshotVersion();
|
|
184
|
+
let subscribedSlot = void 0;
|
|
185
|
+
return {
|
|
186
|
+
snapshotVersion,
|
|
187
|
+
subscribe: (onStoreChange) => {
|
|
188
|
+
const holdingSlot = singleSlotService.holdSingleSlot(singleSlotStoreSlot);
|
|
189
|
+
try {
|
|
190
|
+
oimAssertOneChannel(db, holdingSlot, hookName);
|
|
191
|
+
const disposeEffect = snapshotVersion.subscribeEffect(db, [holdingSlot], [], onStoreChange);
|
|
192
|
+
subscribedSlot = holdingSlot;
|
|
193
|
+
return () => {
|
|
194
|
+
subscribedSlot = void 0;
|
|
195
|
+
disposeEffect();
|
|
196
|
+
};
|
|
197
|
+
} finally {
|
|
198
|
+
holdingSlot.owner.unholdSlot(holdingSlot);
|
|
592
199
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
unsubscribeFromIndex();
|
|
596
|
-
unsubscribeFromCollection();
|
|
597
|
-
};
|
|
200
|
+
},
|
|
201
|
+
getSlot: () => subscribedSlot ?? singleSlotService.getSingleSlot(singleSlotStoreSlot)
|
|
598
202
|
};
|
|
599
|
-
}, [
|
|
600
|
-
|
|
601
|
-
return
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
203
|
+
}, [hookName, db, singleSlotService, singleSlotStoreSlot]);
|
|
204
|
+
useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
|
|
205
|
+
return store.getSlot();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/useOIMSingleEntity.ts
|
|
209
|
+
function useOIMSingleEntity(singleSlotService, singleSlotStoreSlot) {
|
|
210
|
+
return useOIMSingleSlot("useOIMSingleEntity", singleSlotService, singleSlotStoreSlot).entity;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/useOIMSingleBucketSlots.ts
|
|
214
|
+
function useOIMSingleBucketSlots(singleSlotService, singleSlotStoreSlot) {
|
|
215
|
+
const bucketSlot = useOIMSingleSlot("useOIMSingleBucketSlots", singleSlotService, singleSlotStoreSlot);
|
|
216
|
+
return Array.from(singleSlotService.slotContentService.getBucketMemberSlots(bucketSlot));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/useOIMField.ts
|
|
220
|
+
var import_react8 = require("react");
|
|
221
|
+
|
|
222
|
+
// src/holdWhileSubscribed.ts
|
|
223
|
+
var import_core4 = require("@oimdb/core");
|
|
224
|
+
function holdWhileSubscribed(slots, subscribe) {
|
|
225
|
+
(0, import_core4.oimHoldSlots)(slots);
|
|
226
|
+
const giveEveryHoldBack = () => {
|
|
227
|
+
(0, import_core4.oimUnholdSlotsIfAlive)(slots);
|
|
228
|
+
};
|
|
229
|
+
let disposer;
|
|
230
|
+
try {
|
|
231
|
+
disposer = subscribe();
|
|
232
|
+
} catch (failure) {
|
|
233
|
+
giveEveryHoldBack();
|
|
234
|
+
throw failure;
|
|
608
235
|
}
|
|
609
|
-
return
|
|
236
|
+
return () => {
|
|
237
|
+
try {
|
|
238
|
+
disposer();
|
|
239
|
+
} finally {
|
|
240
|
+
giveEveryHoldBack();
|
|
241
|
+
}
|
|
242
|
+
};
|
|
610
243
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
var useSelectPksByCompositeIndexKeyArrayBased = (reactiveIndex, key) => {
|
|
628
|
-
const stableKey = useStableKeyPath(key);
|
|
629
|
-
const snapshotValueRef = (0, import_react3.useRef)();
|
|
630
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
631
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(stableKey);
|
|
632
|
-
return (onStoreChange) => {
|
|
633
|
-
const updateSnapshot = () => {
|
|
634
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(stableKey);
|
|
635
|
-
onStoreChange();
|
|
636
|
-
};
|
|
637
|
-
return reactiveIndex.subscribeOnKey(stableKey, updateSnapshot);
|
|
638
|
-
};
|
|
639
|
-
}, [stableKey, reactiveIndex]);
|
|
640
|
-
const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotValueRef.current, []);
|
|
641
|
-
return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
642
|
-
};
|
|
643
|
-
var useSelectEntitiesByCompositeIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
|
|
644
|
-
const stableKey = useStableKeyPath(key);
|
|
645
|
-
const snapshotRef = (0, import_react3.useRef)();
|
|
646
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
647
|
-
const readSnapshot = () => Array.from(
|
|
648
|
-
reactiveIndex.getPksByKey(stableKey),
|
|
649
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
650
|
-
);
|
|
651
|
-
const readPks = () => Array.from(reactiveIndex.getPksByKey(stableKey));
|
|
652
|
-
snapshotRef.current = readSnapshot();
|
|
653
|
-
return (onStoreChange) => {
|
|
654
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
655
|
-
snapshotRef.current = readSnapshot();
|
|
656
|
-
onStoreChange();
|
|
657
|
-
});
|
|
658
|
-
const resubscribeCollection = () => {
|
|
659
|
-
unsubscribeFromCollection();
|
|
660
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
661
|
-
readPks(),
|
|
662
|
-
() => {
|
|
663
|
-
snapshotRef.current = readSnapshot();
|
|
664
|
-
onStoreChange();
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
};
|
|
668
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(
|
|
669
|
-
stableKey,
|
|
670
|
-
() => {
|
|
671
|
-
resubscribeCollection();
|
|
672
|
-
snapshotRef.current = readSnapshot();
|
|
673
|
-
onStoreChange();
|
|
674
|
-
}
|
|
675
|
-
);
|
|
676
|
-
return () => {
|
|
677
|
-
unsubscribeFromIndex();
|
|
678
|
-
unsubscribeFromCollection();
|
|
679
|
-
};
|
|
680
|
-
};
|
|
681
|
-
}, [stableKey, reactiveCollection, reactiveIndex]);
|
|
682
|
-
const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
|
|
683
|
-
return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
684
|
-
};
|
|
685
|
-
var useSelectEntitiesByCompositeIndexKeyArrayBased = (reactiveCollection, reactiveIndex, key) => {
|
|
686
|
-
const stableKey = useStableKeyPath(key);
|
|
687
|
-
const snapshotRef = (0, import_react3.useRef)();
|
|
688
|
-
const subscribe = (0, import_react3.useMemo)(() => {
|
|
689
|
-
const readSnapshot = () => reactiveIndex.getPksByKey(stableKey).map((pk) => reactiveCollection.getOneByPk(pk));
|
|
690
|
-
const readPks = () => reactiveIndex.getPksByKey(stableKey);
|
|
691
|
-
snapshotRef.current = readSnapshot();
|
|
692
|
-
return (onStoreChange) => {
|
|
693
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
694
|
-
snapshotRef.current = readSnapshot();
|
|
695
|
-
onStoreChange();
|
|
696
|
-
});
|
|
697
|
-
const resubscribeCollection = () => {
|
|
698
|
-
unsubscribeFromCollection();
|
|
699
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
700
|
-
readPks(),
|
|
701
|
-
() => {
|
|
702
|
-
snapshotRef.current = readSnapshot();
|
|
703
|
-
onStoreChange();
|
|
704
|
-
}
|
|
705
|
-
);
|
|
706
|
-
};
|
|
707
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(
|
|
708
|
-
stableKey,
|
|
709
|
-
() => {
|
|
710
|
-
resubscribeCollection();
|
|
711
|
-
snapshotRef.current = readSnapshot();
|
|
712
|
-
onStoreChange();
|
|
713
|
-
}
|
|
714
|
-
);
|
|
715
|
-
return () => {
|
|
716
|
-
unsubscribeFromIndex();
|
|
717
|
-
unsubscribeFromCollection();
|
|
718
|
-
};
|
|
244
|
+
|
|
245
|
+
// src/useOIMField.ts
|
|
246
|
+
function useOIMField(entityCollectionService, slot, name) {
|
|
247
|
+
const db = useOIMDB();
|
|
248
|
+
const store = (0, import_react8.useMemo)(() => {
|
|
249
|
+
oimAssertOneChannel(db, slot, "useOIMField");
|
|
250
|
+
const holds = [slot];
|
|
251
|
+
const snapshotVersion = new OIMSnapshotVersion();
|
|
252
|
+
return {
|
|
253
|
+
snapshotVersion,
|
|
254
|
+
subscribe: (onStoreChange) => holdWhileSubscribed(holds, () => snapshotVersion.subscribeEffect(
|
|
255
|
+
db,
|
|
256
|
+
[entityCollectionService.getColumn(slot, name)],
|
|
257
|
+
[],
|
|
258
|
+
onStoreChange
|
|
259
|
+
))
|
|
719
260
|
};
|
|
720
|
-
}, [
|
|
721
|
-
|
|
722
|
-
return
|
|
723
|
-
}
|
|
261
|
+
}, [db, entityCollectionService, slot, name]);
|
|
262
|
+
useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
|
|
263
|
+
return slot.entity?.[name];
|
|
264
|
+
}
|
|
724
265
|
|
|
725
|
-
// src/
|
|
726
|
-
var
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
{
|
|
730
|
-
);
|
|
731
|
-
|
|
732
|
-
|
|
266
|
+
// src/useOIMBucketSlots.ts
|
|
267
|
+
var import_react9 = require("react");
|
|
268
|
+
function useOIMBucketSlots(bucketCollectionService, bucketSlot) {
|
|
269
|
+
const db = useOIMDB();
|
|
270
|
+
const binding = (0, import_react9.useMemo)(() => {
|
|
271
|
+
oimAssertOneChannel(db, bucketSlot, "useOIMBucketSlots");
|
|
272
|
+
return { sourceSlots: [bucketSlot], derive: () => bucketSlot };
|
|
273
|
+
}, [db, bucketSlot]);
|
|
274
|
+
const { changedAtRevision, changedAtEpoch } = useOIMValue(binding);
|
|
275
|
+
return (0, import_react9.useMemo)(
|
|
276
|
+
() => Array.from(bucketCollectionService.slotContentService.getBucketMemberSlots(bucketSlot)),
|
|
277
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- the bucket slot's change stamp moves exactly when its members do
|
|
278
|
+
[bucketCollectionService, bucketSlot, changedAtRevision, changedAtEpoch]
|
|
279
|
+
);
|
|
733
280
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
281
|
+
|
|
282
|
+
// src/useOIMBucketSlotsByKey.ts
|
|
283
|
+
function useOIMBucketSlotsByKey(bucketCollectionService, bucketStoreSlot, key) {
|
|
284
|
+
const bucketSlot = useOIMSlotByKey("useOIMBucketSlotsByKey", bucketCollectionService, bucketStoreSlot, key);
|
|
285
|
+
return Array.from(bucketCollectionService.slotContentService.getBucketMemberSlots(bucketSlot));
|
|
737
286
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
287
|
+
|
|
288
|
+
// src/useOIMSlotsByKeys.ts
|
|
289
|
+
var import_react10 = require("react");
|
|
290
|
+
var import_core5 = require("@oimdb/core");
|
|
291
|
+
function useOIMSlotsByKeys(slotCollectionService, storeSlot, keys) {
|
|
292
|
+
const settledKeys = (0, import_react10.useRef)(keys);
|
|
293
|
+
const previousKeys = settledKeys.current;
|
|
294
|
+
if (!(0, import_core5.oimSameKeySequence)(previousKeys, keys)) settledKeys.current = keys;
|
|
295
|
+
const keysToHold = settledKeys.current;
|
|
296
|
+
const [, resolveAgain] = (0, import_react10.useState)(0);
|
|
297
|
+
const resolvedSlots = (0, import_react10.useRef)(void 0);
|
|
298
|
+
const resolvedKeys = (0, import_react10.useRef)(keysToHold);
|
|
299
|
+
const resolvedSlotCollectionService = (0, import_react10.useRef)(slotCollectionService);
|
|
300
|
+
const resolvedStoreSlot = (0, import_react10.useRef)(storeSlot);
|
|
301
|
+
if (resolvedSlots.current === void 0 || resolvedKeys.current !== keysToHold || resolvedSlotCollectionService.current !== slotCollectionService || resolvedStoreSlot.current !== storeSlot) {
|
|
302
|
+
const slots2 = [];
|
|
303
|
+
for (let i = 0; i < keysToHold.length; i++) {
|
|
304
|
+
slots2.push(slotCollectionService.getSlotByKey(storeSlot, keysToHold[i]));
|
|
305
|
+
}
|
|
306
|
+
resolvedSlots.current = slots2;
|
|
307
|
+
resolvedKeys.current = keysToHold;
|
|
308
|
+
resolvedSlotCollectionService.current = slotCollectionService;
|
|
309
|
+
resolvedStoreSlot.current = storeSlot;
|
|
745
310
|
}
|
|
746
|
-
|
|
311
|
+
const slots = resolvedSlots.current;
|
|
312
|
+
(0, import_react10.useEffect)(() => {
|
|
313
|
+
const renderedSlots = resolvedSlots.current;
|
|
314
|
+
const heldSlots = [];
|
|
315
|
+
let someKeyNamesAnotherIdentityNow = false;
|
|
316
|
+
for (let i = 0; i < keysToHold.length; i++) {
|
|
317
|
+
const slot = slotCollectionService.holdSlotByKey(storeSlot, keysToHold[i]);
|
|
318
|
+
heldSlots.push(slot);
|
|
319
|
+
if (slot !== renderedSlots?.[i]) someKeyNamesAnotherIdentityNow = true;
|
|
320
|
+
}
|
|
321
|
+
if (someKeyNamesAnotherIdentityNow) {
|
|
322
|
+
resolvedSlots.current = void 0;
|
|
323
|
+
resolveAgain((version) => version + 1);
|
|
324
|
+
}
|
|
325
|
+
return () => {
|
|
326
|
+
for (let i = 0; i < heldSlots.length; i++) {
|
|
327
|
+
const heldSlot = heldSlots[i];
|
|
328
|
+
heldSlot.owner.unholdSlot(heldSlot);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}, [slotCollectionService, storeSlot, keysToHold]);
|
|
332
|
+
return slots;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/useOIMComputedValueByKey.ts
|
|
336
|
+
var import_core6 = require("@oimdb/core");
|
|
337
|
+
var sourcesOfComputedSlot = (computedSlot) => [import_core6.OIM_FROZEN_EMPTY_SLOTS, [computedSlot]];
|
|
338
|
+
function useOIMComputedValueByKey(computedCollectionService, computedStoreSlot, key) {
|
|
339
|
+
const computedSlot = useOIMSlotByKey(
|
|
340
|
+
"useOIMComputedValueByKey",
|
|
341
|
+
computedCollectionService,
|
|
342
|
+
computedStoreSlot,
|
|
343
|
+
key,
|
|
344
|
+
sourcesOfComputedSlot
|
|
345
|
+
);
|
|
346
|
+
return computedSlot.computedValueService.getValueForSlot(computedSlot);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/useOIMSingleComputedValue.ts
|
|
350
|
+
var import_react11 = require("react");
|
|
351
|
+
function useOIMSingleComputedValue(computedService, derive, createSources, dependencyList) {
|
|
352
|
+
const db = useOIMDB();
|
|
353
|
+
const computedStoreSlot = (0, import_react11.useMemo)(
|
|
354
|
+
() => computedService.createComputedStoreSlot(db, derive, createSources),
|
|
355
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- the caller's list is checked at the call site
|
|
356
|
+
[db, computedService, ...dependencyList]
|
|
357
|
+
);
|
|
358
|
+
return useOIMComputedValueByKey(
|
|
359
|
+
computedService.computedCollectionService,
|
|
360
|
+
computedStoreSlot,
|
|
361
|
+
void 0
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/useOIMComputedCollection.ts
|
|
366
|
+
var import_react12 = require("react");
|
|
367
|
+
function useOIMComputedCollection(computedService, derive, createSources, dependencyList) {
|
|
368
|
+
const db = useOIMDB();
|
|
369
|
+
return (0, import_react12.useMemo)(
|
|
370
|
+
() => computedService.createComputedStoreSlot(db, derive, createSources),
|
|
371
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- the caller's list is checked at the call site
|
|
372
|
+
[db, computedService, ...dependencyList]
|
|
373
|
+
);
|
|
747
374
|
}
|
|
748
375
|
// Annotate the CommonJS export names for ESM import in node:
|
|
749
376
|
0 && (module.exports = {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
useSelectPksByCompositeIndexKeyArrayBased,
|
|
766
|
-
useSelectPksByCompositeIndexKeySetBased,
|
|
767
|
-
useSelectPksByGlobalIndexArrayBased,
|
|
768
|
-
useSelectPksByGlobalIndexArrayBasedSignal,
|
|
769
|
-
useSelectPksByGlobalIndexSetBased,
|
|
770
|
-
useSelectPksByGlobalIndexSetBasedSignal,
|
|
771
|
-
useSelectPksByIndexKeyArrayBased,
|
|
772
|
-
useSelectPksByIndexKeyArrayBasedSignal,
|
|
773
|
-
useSelectPksByIndexKeySetBased,
|
|
774
|
-
useSelectPksByIndexKeySetBasedSignal,
|
|
775
|
-
useSelectPksByIndexKeysArrayBased,
|
|
776
|
-
useSelectPksByIndexKeysSetBased,
|
|
777
|
-
useSelectValueByObjectKey,
|
|
778
|
-
useSelectValuesByObjectKeys
|
|
377
|
+
OIMDBContext,
|
|
378
|
+
OIMDBProvider,
|
|
379
|
+
useOIMBucketSlots,
|
|
380
|
+
useOIMBucketSlotsByKey,
|
|
381
|
+
useOIMComputedCollection,
|
|
382
|
+
useOIMComputedValue,
|
|
383
|
+
useOIMComputedValueByKey,
|
|
384
|
+
useOIMDB,
|
|
385
|
+
useOIMEntity,
|
|
386
|
+
useOIMField,
|
|
387
|
+
useOIMSingleBucketSlots,
|
|
388
|
+
useOIMSingleComputedValue,
|
|
389
|
+
useOIMSingleEntity,
|
|
390
|
+
useOIMSlotsByKeys,
|
|
391
|
+
useOIMValue
|
|
779
392
|
});
|