@oimdb/react 2.1.2 → 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 +267 -127
- package/dist/index.cjs +343 -466
- package/dist/index.d.cts +56 -34
- package/dist/index.d.ts +56 -34
- package/dist/index.js +328 -447
- package/llms.txt +4156 -0
- package/package.json +46 -36
package/dist/index.cjs
CHANGED
|
@@ -20,496 +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
|
-
useSelectPksByIndexKeysArrayBased: () => useSelectPksByIndexKeysArrayBased,
|
|
39
|
-
useSelectPksByIndexKeysSetBased: () => useSelectPksByIndexKeysSetBased,
|
|
40
|
-
useSelectValueByObjectKey: () => useSelectValueByObjectKey,
|
|
41
|
-
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
|
|
42
38
|
});
|
|
43
39
|
module.exports = __toCommonJS(index_exports);
|
|
44
40
|
|
|
45
|
-
// src/
|
|
46
|
-
var import_react2 = require("react");
|
|
47
|
-
var import_react3 = require("react");
|
|
48
|
-
|
|
49
|
-
// src/hooks/signal.ts
|
|
41
|
+
// src/OIMDBContext.ts
|
|
50
42
|
var import_react = require("react");
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
var OIMDBContext = (0, import_react.createContext)(void 0);
|
|
44
|
+
|
|
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 });
|
|
55
49
|
}
|
|
56
|
-
var useSelectEntityByPkSignal = (reactiveCollection, pk) => {
|
|
57
|
-
const force = useForceUpdate();
|
|
58
|
-
useIsomorphicLayoutEffect(
|
|
59
|
-
() => reactiveCollection.subscribeOnKey(pk, force),
|
|
60
|
-
[reactiveCollection, pk]
|
|
61
|
-
);
|
|
62
|
-
return reactiveCollection.getOneByPk(pk);
|
|
63
|
-
};
|
|
64
|
-
var useSelectPksByIndexKeyArrayBasedSignal = (reactiveIndex, key) => {
|
|
65
|
-
const force = useForceUpdate();
|
|
66
|
-
useIsomorphicLayoutEffect(
|
|
67
|
-
() => reactiveIndex.subscribeOnKey(key, force),
|
|
68
|
-
[reactiveIndex, key]
|
|
69
|
-
);
|
|
70
|
-
return reactiveIndex.getPksByKey(key);
|
|
71
|
-
};
|
|
72
|
-
var useSelectPksByIndexKeySetBasedSignal = (reactiveIndex, key) => {
|
|
73
|
-
const force = useForceUpdate();
|
|
74
|
-
useIsomorphicLayoutEffect(
|
|
75
|
-
() => reactiveIndex.subscribeOnKey(key, force),
|
|
76
|
-
[reactiveIndex, key]
|
|
77
|
-
);
|
|
78
|
-
return reactiveIndex.getPksByKey(key);
|
|
79
|
-
};
|
|
80
50
|
|
|
81
|
-
// src/
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
);
|
|
88
59
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return () => {
|
|
103
|
-
unsubscribe();
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
}, [reactiveIndex, stableKeys]);
|
|
107
|
-
const getSnapshot = (0, import_react2.useMemo)(() => {
|
|
108
|
-
return () => {
|
|
109
|
-
return snapshotValueRef.current;
|
|
110
|
-
};
|
|
111
|
-
}, []);
|
|
112
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
113
|
-
return snapshot;
|
|
114
|
-
};
|
|
115
|
-
var useSelectPksByIndexKeySetBased = (reactiveIndex, key) => {
|
|
116
|
-
const snapshotValueRef = (0, import_react2.useRef)();
|
|
117
|
-
const subscribe = (0, import_react2.useMemo)(() => {
|
|
118
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
119
|
-
return (onStoreChange) => {
|
|
120
|
-
const updateSnapshot = () => {
|
|
121
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
122
|
-
onStoreChange();
|
|
123
|
-
};
|
|
124
|
-
return reactiveIndex.subscribeOnKey(key, updateSnapshot);
|
|
125
|
-
};
|
|
126
|
-
}, [key, reactiveIndex]);
|
|
127
|
-
const getSnapshot = (0, import_react2.useMemo)(() => {
|
|
128
|
-
return () => {
|
|
129
|
-
return snapshotValueRef.current;
|
|
130
|
-
};
|
|
131
|
-
}, []);
|
|
132
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
133
|
-
return snapshot;
|
|
134
|
-
};
|
|
135
|
-
var useSelectPksByIndexKeysArrayBased = (reactiveIndex, keys) => {
|
|
136
|
-
const prevKeysRef = (0, import_react2.useRef)();
|
|
137
|
-
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
138
|
-
if (!keysAreEqual) {
|
|
139
|
-
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;
|
|
140
73
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
snapshotValueRef.current = stableKeys.map((key) => reactiveIndex.getPksByKey(key)).flat();
|
|
148
|
-
onStoreChange();
|
|
149
|
-
};
|
|
150
|
-
const unsubscribe = reactiveIndex.subscribeOnKeys(
|
|
151
|
-
stableKeys,
|
|
152
|
-
updateSnapshot
|
|
153
|
-
);
|
|
154
|
-
return () => {
|
|
155
|
-
unsubscribe();
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
}, [reactiveIndex, stableKeys]);
|
|
159
|
-
const getSnapshot = (0, import_react2.useMemo)(() => {
|
|
160
|
-
return () => {
|
|
161
|
-
return snapshotValueRef.current;
|
|
162
|
-
};
|
|
163
|
-
}, []);
|
|
164
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
165
|
-
return snapshot;
|
|
166
|
-
};
|
|
167
|
-
var useSelectPksByIndexKeyArrayBased = (reactiveIndex, key) => {
|
|
168
|
-
const prevKeyRef = (0, import_react2.useRef)();
|
|
169
|
-
const keyAreEqual = prevKeyRef.current === key;
|
|
170
|
-
if (!keyAreEqual) {
|
|
171
|
-
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
|
+
});
|
|
172
80
|
}
|
|
173
|
-
const snapshotValueRef = (0, import_react2.useRef)();
|
|
174
|
-
const subscribe = (0, import_react2.useMemo)(() => {
|
|
175
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(key);
|
|
176
|
-
return (onStoreChange) => {
|
|
177
|
-
const prevKey = prevKeyRef.current;
|
|
178
|
-
if (!prevKey) {
|
|
179
|
-
return () => {
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
const updateSnapshot = () => {
|
|
183
|
-
snapshotValueRef.current = reactiveIndex.getPksByKey(prevKey);
|
|
184
|
-
onStoreChange();
|
|
185
|
-
};
|
|
186
|
-
const unsubscribe = reactiveIndex.subscribeOnKey(
|
|
187
|
-
prevKey,
|
|
188
|
-
updateSnapshot
|
|
189
|
-
);
|
|
190
|
-
return () => {
|
|
191
|
-
unsubscribe();
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
}, [key, reactiveIndex]);
|
|
195
|
-
const getSnapshot = (0, import_react2.useMemo)(() => {
|
|
196
|
-
return () => {
|
|
197
|
-
return snapshotValueRef.current;
|
|
198
|
-
};
|
|
199
|
-
}, []);
|
|
200
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
201
|
-
return snapshot;
|
|
202
81
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
)
|
|
211
103
|
};
|
|
212
|
-
}, [
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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.`
|
|
220
130
|
);
|
|
221
|
-
const subscribe = (0, import_react2.useMemo)(() => {
|
|
222
|
-
return (onStoreChange) => {
|
|
223
|
-
return reactiveObject.subscribeOnKey(key, onStoreChange);
|
|
224
|
-
};
|
|
225
|
-
}, [key, reactiveObject]);
|
|
226
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
227
|
-
return snapshot;
|
|
228
|
-
};
|
|
229
|
-
var useSelectValuesByObjectKeys = (reactiveObject, keys) => {
|
|
230
|
-
const prevKeysRef = (0, import_react2.useRef)();
|
|
231
|
-
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
232
|
-
if (!keysAreEqual) {
|
|
233
|
-
prevKeysRef.current = keys;
|
|
234
|
-
}
|
|
235
|
-
const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
|
|
236
|
-
const snapshotRef = (0, import_react2.useRef)();
|
|
237
|
-
const subscribe = (0, import_react2.useMemo)(() => {
|
|
238
|
-
snapshotRef.current = stableKeys.map((key) => reactiveObject.get(key));
|
|
239
|
-
return (onStoreChange) => {
|
|
240
|
-
const updateSnapshot = () => {
|
|
241
|
-
snapshotRef.current = stableKeys.map(
|
|
242
|
-
(key) => reactiveObject.get(key)
|
|
243
|
-
);
|
|
244
|
-
onStoreChange();
|
|
245
|
-
};
|
|
246
|
-
const unsubscribe = reactiveObject.subscribeOnKeys(
|
|
247
|
-
stableKeys,
|
|
248
|
-
updateSnapshot
|
|
249
|
-
);
|
|
250
|
-
return () => {
|
|
251
|
-
unsubscribe();
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
}, [reactiveObject, stableKeys]);
|
|
255
|
-
const getSnapshot = (0, import_react2.useMemo)(() => {
|
|
256
|
-
return () => {
|
|
257
|
-
return snapshotRef.current;
|
|
258
|
-
};
|
|
259
|
-
}, []);
|
|
260
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
261
|
-
return snapshot;
|
|
262
|
-
};
|
|
263
|
-
function arraysEqual(a, b) {
|
|
264
|
-
if (a === b) return true;
|
|
265
|
-
if (a.length !== b.length) return false;
|
|
266
|
-
for (let i = 0; i < a.length; i++) {
|
|
267
|
-
if (a[i] !== b[i]) return false;
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
131
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return (onStoreChange) => {
|
|
284
|
-
const updateSnapshot = () => {
|
|
285
|
-
snapshotRef.current = stablePks.map(
|
|
286
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
287
|
-
);
|
|
288
|
-
onStoreChange();
|
|
289
|
-
};
|
|
290
|
-
const unsubscribe = reactiveCollection.subscribeOnKeys(
|
|
291
|
-
stablePks,
|
|
292
|
-
updateSnapshot
|
|
293
|
-
);
|
|
294
|
-
return () => {
|
|
295
|
-
unsubscribe();
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
}, [reactiveCollection, stablePks]);
|
|
299
|
-
const getSnapshot = (0, import_react2.useMemo)(() => {
|
|
300
|
-
return () => {
|
|
301
|
-
return snapshotRef.current;
|
|
302
|
-
};
|
|
303
|
-
}, []);
|
|
304
|
-
const snapshot = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
305
|
-
return snapshot;
|
|
306
|
-
};
|
|
307
|
-
var useSelectEntitiesByIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
|
|
308
|
-
const snapshotRef = (0, import_react2.useRef)();
|
|
309
|
-
const subscribe = (0, import_react2.useMemo)(() => {
|
|
310
|
-
const readSnapshot = () => Array.from(
|
|
311
|
-
reactiveIndex.getPksByKey(key),
|
|
312
|
-
(pk) => reactiveCollection.getOneByPk(pk)
|
|
313
|
-
);
|
|
314
|
-
const readPks = () => Array.from(reactiveIndex.getPksByKey(key));
|
|
315
|
-
snapshotRef.current = readSnapshot();
|
|
316
|
-
return (onStoreChange) => {
|
|
317
|
-
let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
|
|
318
|
-
snapshotRef.current = readSnapshot();
|
|
319
|
-
onStoreChange();
|
|
320
|
-
});
|
|
321
|
-
const resubscribeCollection = () => {
|
|
322
|
-
unsubscribeFromCollection();
|
|
323
|
-
unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
|
|
324
|
-
readPks(),
|
|
325
|
-
() => {
|
|
326
|
-
snapshotRef.current = readSnapshot();
|
|
327
|
-
onStoreChange();
|
|
328
|
-
}
|
|
329
|
-
);
|
|
330
|
-
};
|
|
331
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
|
|
332
|
-
resubscribeCollection();
|
|
333
|
-
snapshotRef.current = readSnapshot();
|
|
334
|
-
onStoreChange();
|
|
335
|
-
});
|
|
336
|
-
return () => {
|
|
337
|
-
unsubscribeFromIndex();
|
|
338
|
-
unsubscribeFromCollection();
|
|
339
|
-
};
|
|
340
|
-
};
|
|
341
|
-
}, [key, reactiveCollection, reactiveIndex]);
|
|
342
|
-
const getSnapshot = (0, import_react2.useMemo)(() => () => snapshotRef.current, []);
|
|
343
|
-
return (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
344
|
-
};
|
|
345
|
-
var useSelectEntitiesByIndexKeysSetBased = (reactiveCollection, reactiveIndex, keys) => {
|
|
346
|
-
const prevKeysRef = (0, import_react2.useRef)();
|
|
347
|
-
const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
|
|
348
|
-
if (!keysAreEqual) {
|
|
349
|
-
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
|
+
}
|
|
350
144
|
}
|
|
351
|
-
const
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
onStoreChange();
|
|
371
|
-
}
|
|
372
|
-
);
|
|
373
|
-
};
|
|
374
|
-
const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
|
|
375
|
-
stableKeys,
|
|
376
|
-
() => {
|
|
377
|
-
resubscribeCollection();
|
|
378
|
-
snapshotRef.current = readSnapshot();
|
|
379
|
-
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);
|
|
380
164
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
unsubscribeFromIndex();
|
|
384
|
-
unsubscribeFromCollection();
|
|
385
|
-
};
|
|
165
|
+
},
|
|
166
|
+
getSlot: () => subscribedSlot ?? slotCollectionService.getSlotByKey(storeSlot, settledKey)
|
|
386
167
|
};
|
|
387
|
-
}, [
|
|
388
|
-
|
|
389
|
-
return
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
getSlot: () => subscribedSlot ?? singleSlotService.getSingleSlot(singleSlotStoreSlot)
|
|
421
202
|
};
|
|
422
|
-
}, [
|
|
423
|
-
|
|
424
|
-
return
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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;
|
|
431
235
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
resubscribeCollection();
|
|
457
|
-
snapshotRef.current = readSnapshot();
|
|
458
|
-
onStoreChange();
|
|
459
|
-
}
|
|
460
|
-
);
|
|
461
|
-
return () => {
|
|
462
|
-
unsubscribeFromIndex();
|
|
463
|
-
unsubscribeFromCollection();
|
|
464
|
-
};
|
|
236
|
+
return () => {
|
|
237
|
+
try {
|
|
238
|
+
disposer();
|
|
239
|
+
} finally {
|
|
240
|
+
giveEveryHoldBack();
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
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
|
+
))
|
|
465
260
|
};
|
|
466
|
-
}, [
|
|
467
|
-
|
|
468
|
-
return
|
|
469
|
-
}
|
|
261
|
+
}, [db, entityCollectionService, slot, name]);
|
|
262
|
+
useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
|
|
263
|
+
return slot.entity?.[name];
|
|
264
|
+
}
|
|
470
265
|
|
|
471
|
-
// src/
|
|
472
|
-
var
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
{
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
|
|
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
|
+
);
|
|
479
280
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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));
|
|
483
286
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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;
|
|
491
310
|
}
|
|
492
|
-
|
|
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
|
+
);
|
|
493
374
|
}
|
|
494
375
|
// Annotate the CommonJS export names for ESM import in node:
|
|
495
376
|
0 && (module.exports = {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
useSelectPksByIndexKeysArrayBased,
|
|
512
|
-
useSelectPksByIndexKeysSetBased,
|
|
513
|
-
useSelectValueByObjectKey,
|
|
514
|
-
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
|
|
515
392
|
});
|