@oimdb/react 3.0.0 → 3.1.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 +24 -31
- package/dist/index.cjs +49 -45
- package/dist/index.d.cts +17 -13
- package/dist/index.d.ts +17 -13
- package/dist/index.js +44 -40
- package/llms.txt +962 -1042
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install @oimdb/react @oimdb/core
|
|
|
11
11
|
|
|
12
12
|
## Why one binding
|
|
13
13
|
|
|
14
|
-
Subscribing in this engine is one call: `OIMEffectService.INSTANCE.subscribeEffect(db,
|
|
14
|
+
Subscribing in this engine is one call: `OIMEffectService.INSTANCE.subscribeEffect(db, body, sourceSlots?, sourceComputeds?, sourceTrackingComputeds?)`.
|
|
15
15
|
It carries no value; what changed is read off the slots afterwards. So a component needs
|
|
16
16
|
exactly three things: the roots a write can reach, the derivations to ask before reading,
|
|
17
17
|
and the derive function. Together they make up `TOIMBinding`, and `useOIMValue` is the hook that applies it through
|
|
@@ -35,18 +35,18 @@ instance, a store slot, and every store door of the service takes that store slo
|
|
|
35
35
|
Whatever a read mints is swept at the end of the frame unless something took a real reference to it.
|
|
36
36
|
|
|
37
37
|
```ts setup
|
|
38
|
-
import { OIMDB,
|
|
38
|
+
import { OIMDB, type TOIMEntitySlot, createOIMSlotCollectionService, createOIMSlotContentEntityService, OIMSlotContentPositionalArrayBucketService, OIMBucketCommands, createOIMSingleComputedService, OIMSingleSlotStoreService, createOIMSingleSlotService, createOIMComputedService, oimSameValueZeroGuard, type TOIMComputedSlot } from '@oimdb/core';
|
|
39
39
|
|
|
40
40
|
type TCard = { id: string; deckId: string; title: string; rank: number };
|
|
41
41
|
|
|
42
42
|
export const db = new OIMDB();
|
|
43
43
|
|
|
44
|
-
export const cardService =
|
|
44
|
+
export const cardService = createOIMSlotCollectionService({ slotContentService: createOIMSlotContentEntityService<TCard>() });
|
|
45
45
|
export const cards = cardService.createStoreSlot(db);
|
|
46
46
|
|
|
47
47
|
// A bucket keeps the order the caller writes; a sorted list is
|
|
48
|
-
// `
|
|
49
|
-
export const byDeckService =
|
|
48
|
+
// `createOIMSortedComputedService` over an index.
|
|
49
|
+
export const byDeckService = createOIMSlotCollectionService({ slotContentService: new OIMSlotContentPositionalArrayBucketService<TOIMEntitySlot<TCard>>({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: undefined }) }) });
|
|
50
50
|
export const byDeck = byDeckService.createStoreSlot(db);
|
|
51
51
|
|
|
52
52
|
// A BUCKET'S SLOTS ARE YOURS. A write moves the card's value and files nothing, so the
|
|
@@ -54,9 +54,9 @@ export const byDeck = byDeckService.createStoreSlot(db);
|
|
|
54
54
|
// bucket by key: it mints one if there is none and hands back the bucket itself,
|
|
55
55
|
// counted. `owner.unholdSlot` gives that count back, once the bucket's own slots keep it.
|
|
56
56
|
export function setDeck(deckId: string, cardsInDeck: readonly TCard[]): void {
|
|
57
|
-
cardService.
|
|
57
|
+
cardService.writeInBatch(cards, () => (cardsInDeck).map(entity => cardService.writeSlotContentByKey(cards, entity.id, entity)));
|
|
58
58
|
const bucket = byDeckService.holdSlotByKey(byDeck, deckId);
|
|
59
|
-
byDeckService.slotContentService.
|
|
59
|
+
byDeckService.slotContentService.writeSlotContent(
|
|
60
60
|
bucket, cardsInDeck.map((card) => cardService.getSlotByKey(cards, card.id)),
|
|
61
61
|
);
|
|
62
62
|
bucket.owner.unholdSlot(bucket);
|
|
@@ -131,7 +131,7 @@ The parameter is typed as a `Pick` of `OIMSlotCollectionService` with only the m
|
|
|
131
131
|
entity slots. It resolves the bucket on commit, holds it for as long as the component is mounted, and gives the
|
|
132
132
|
hold back on unmount or when the key changes. It copies the members on every render: the bucket it reads during a
|
|
133
133
|
render may be held by nothing yet, and an unheld bucket's stamp does not move. **The key may be built inline**,
|
|
134
|
-
including the array that keys an `
|
|
134
|
+
including the array that keys an `OIMSlotTreeStoreService`; the hook settles it by asking the store which
|
|
135
135
|
bucket each key names.
|
|
136
136
|
- **`useOIMSlotsByKeys(slotCollectionService, storeSlot, keys)`**: several identities of one store slot,
|
|
137
137
|
resolved by key and held for as long as the component is mounted. It returns the slots and takes no subscription,
|
|
@@ -146,26 +146,21 @@ The parameter is typed as a `Pick` of `OIMSlotCollectionService` with only the m
|
|
|
146
146
|
only calls `computedService.createComputedStoreSlot(db, derive, createSources)` in a `useMemo` keyed on `deps`, and
|
|
147
147
|
returns that store slot. `derive` and `createSources` may be `undefined` when the service already has them.
|
|
148
148
|
Read it by key with `useOIMComputedValueByKey(computedService.computedCollectionService, computedStoreSlot, key)`.
|
|
149
|
-
- **`useOIMSingleComputedValue(computedService, derive, createSources, deps)`**: a single computed the
|
|
150
|
-
owns
|
|
151
|
-
`
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
- **`useOIMSingleComputedValue(computedService, derive, createSources, deps)`**: a single computed the
|
|
150
|
+
component owns. The service is `createOIMSingleComputedService<V>()`, built once at module scope; `derive` and
|
|
151
|
+
`createSources` receive the computed slot. Per mount the hook builds one store slot and reads its slot through
|
|
152
|
+
`computedSingleSlotService`, so a flush between render and subscribe, which releases the slot the render minted,
|
|
153
|
+
is safe.
|
|
154
154
|
- **`useOIMSingleEntity(singleSlotService, singleSlotStoreSlot)`** and
|
|
155
155
|
**`useOIMSingleBucketSlots(singleSlotService, singleSlotStoreSlot)`**: the single entity and the single bucket.
|
|
156
156
|
See [Singles](#singles).
|
|
157
157
|
- **`useOIMDB()`**: the `OIMDB` from `OIMDBContext`. It throws if used outside `<OIMDBProvider>`.
|
|
158
158
|
|
|
159
159
|
```tsx
|
|
160
|
-
import { OIMSlotStoreServiceSingleSlotDriven, createOIMComputedService } from '@oimdb/core';
|
|
161
|
-
import type { TOIMComputedSlot, TOIMSingleSlotStore } from '@oimdb/core';
|
|
162
160
|
import { useOIMSingleComputedValue } from '@oimdb/react';
|
|
163
161
|
|
|
164
162
|
// Module scope: one service per kind of computed, shared by every component.
|
|
165
|
-
const totalRankService =
|
|
166
|
-
computedSlotStoreService:
|
|
167
|
-
OIMSlotStoreServiceSingleSlotDriven.INSTANCE as OIMSlotStoreServiceSingleSlotDriven<TOIMComputedSlot<number, void>>,
|
|
168
|
-
});
|
|
163
|
+
const totalRankService = createOIMSingleComputedService<number>();
|
|
169
164
|
|
|
170
165
|
function TotalRank({ ids }: { ids: readonly string[] }) {
|
|
171
166
|
// Per mount: one store slot with its own derive and sources.
|
|
@@ -181,23 +176,22 @@ function TotalRank({ ids }: { ids: readonly string[] }) {
|
|
|
181
176
|
|
|
182
177
|
## Singles
|
|
183
178
|
|
|
184
|
-
A single is a store slot that holds ONE identity and has no key: `
|
|
185
|
-
`
|
|
179
|
+
A single is a store slot that holds ONE identity and has no key: `createOIMSingleSlotService()` and
|
|
180
|
+
`createOIMSingleSlotService()` hand back an `OIMSingleSlotService`, read through `getSingleSlot(storeSlot)` and
|
|
186
181
|
`holdSingleSlot(storeSlot)`. The two single hooks take that service (typed as a `Pick` of `OIMSingleSlotService`)
|
|
187
182
|
and its store slot, and have the by-key hooks' mechanics without the key: the render reads `getSingleSlot`, whose
|
|
188
183
|
mint the next `flush()` takes back if no commit follows; the commit resolves with `holdSingleSlot`, subscribes over
|
|
189
184
|
that slot and gives the resolve-hold straight back, so a single released while nothing watched it is minted afresh.
|
|
190
185
|
|
|
191
186
|
```tsx
|
|
192
|
-
import { createOIMSingleBucketService, createOIMSingleEntityService } from '@oimdb/core';
|
|
193
187
|
import { useOIMSingleBucketSlots, useOIMSingleEntity } from '@oimdb/react';
|
|
194
188
|
|
|
195
189
|
type TSettings = { theme: string };
|
|
196
190
|
|
|
197
|
-
const settingsService =
|
|
191
|
+
const settingsService = createOIMSingleSlotService({ slotContentService: createOIMSlotContentEntityService<TSettings>() });
|
|
198
192
|
const settings = settingsService.createStoreSlot(db);
|
|
199
193
|
|
|
200
|
-
const pickedService =
|
|
194
|
+
const pickedService = createOIMSingleSlotService({ slotContentService: new OIMSlotContentPositionalArrayBucketService<TOIMEntitySlot<TCard>>({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: undefined }) }) });
|
|
201
195
|
const picked = pickedService.createStoreSlot(db);
|
|
202
196
|
|
|
203
197
|
function Toolbar() {
|
|
@@ -212,7 +206,7 @@ A single computed is `useOIMSingleComputedValue`.
|
|
|
212
206
|
|
|
213
207
|
## Binding a derivation
|
|
214
208
|
|
|
215
|
-
`createOIMComputedService` and `
|
|
209
|
+
`createOIMComputedService` and `createOIMBucketMemoComputedService` both hand back a service of computed slots,
|
|
216
210
|
whose store slot holds them. You can either hold the key where the lifetime is (a module, your own store) and bind
|
|
217
211
|
it with `useOIMValue`, or let the component own the lifetime with `useOIMSlotsByKeys`.
|
|
218
212
|
|
|
@@ -222,7 +216,7 @@ asked and never woken. Only a computed slot's `computedValueService.getValueForS
|
|
|
222
216
|
|
|
223
217
|
**No wake is owed for what happened before the subscription.** An effect is stamped with the channel clock at
|
|
224
218
|
birth (`ranAtRevision` / `ranAtEpoch`), so a frame runs the body only when a source moved *after* the subscription.
|
|
225
|
-
Every hook here subscribes with `subscribeEffect`; `OIMEffectService.INSTANCE.
|
|
219
|
+
Every hook here subscribes with `subscribeEffect`; `OIMEffectService.INSTANCE.createAndRunEffect` is the door
|
|
226
220
|
that delivers a value at once.
|
|
227
221
|
|
|
228
222
|
## Holds per component
|
|
@@ -232,11 +226,10 @@ resolves each key through `holdSlotByKey(storeSlot, key)` and keeps that hold, a
|
|
|
232
226
|
moves) it gives back exactly the holds that commit took.
|
|
233
227
|
|
|
234
228
|
```tsx
|
|
235
|
-
import { createOIMComputedService, oimSameValueZeroGuard } from '@oimdb/core';
|
|
236
229
|
import { useOIMSlotsByKeys } from '@oimdb/react';
|
|
237
230
|
|
|
238
231
|
const rankService = createOIMComputedService<string, number>({
|
|
239
|
-
createSources: (id) => ({ sourceSlots: [cardService.getSlotByKey(cards, id)] }),
|
|
232
|
+
createSources: ({ key: id }) => ({ sourceSlots: [cardService.getSlotByKey(cards, id)] }),
|
|
240
233
|
derive: (computedSlot) => cardService.getSlotByKey(cards, computedSlot.key).entity?.rank ?? -1,
|
|
241
234
|
sameValueGuard: oimSameValueZeroGuard,
|
|
242
235
|
});
|
|
@@ -298,7 +291,7 @@ identity are one key.
|
|
|
298
291
|
|
|
299
292
|
## Things worth knowing
|
|
300
293
|
|
|
301
|
-
- **The snapshot `useOIMValue` compares is a local counter, not the value.** `
|
|
294
|
+
- **The snapshot `useOIMValue` compares is a local counter, not the value.** `createOIMInPlaceEntityWriter` keeps
|
|
302
295
|
an entity's object reference stable, a bucket hands its slots back as the same live container, and a column
|
|
303
296
|
subscription fires only for its own column; a value-comparing binding would fire on none of the three. The counter
|
|
304
297
|
is bumped ON SUBSCRIBING too, so a write that lands between the render and the subscription is still shown. The
|
|
@@ -310,9 +303,9 @@ identity are one key.
|
|
|
310
303
|
is one per kind of computed; a component that owns a computed gets only a store slot from
|
|
311
304
|
`useOIMComputedCollection` / `useOIMSingleComputedValue`.
|
|
312
305
|
- **Nothing re-files an entity when it is written into a bucket you maintain.** Write the buckets in the same code
|
|
313
|
-
that writes the entity, or use an index service (`
|
|
306
|
+
that writes the entity, or use an index service (`createOIMSlotCollectionIndexService`), which files entities by the key it
|
|
314
307
|
derives from each one.
|
|
315
|
-
- **A bucket never sorts.** A list sorted by a column is `
|
|
308
|
+
- **A bucket never sorts.** A list sorted by a column is `createOIMSortedComputedService({ indexService, sortColumns })`
|
|
316
309
|
over an index service, with `createSortedStoreSlot(indexStoreSlot)`.
|
|
317
310
|
|
|
318
311
|
## Reference
|
package/dist/index.cjs
CHANGED
|
@@ -71,12 +71,12 @@ var OIMSnapshotVersion = class {
|
|
|
71
71
|
this.version = 0;
|
|
72
72
|
this.getVersion = () => this.version;
|
|
73
73
|
}
|
|
74
|
-
subscribeEffect(channelMap, sourceSlots, sourceComputeds
|
|
74
|
+
subscribeEffect(channelMap, onStoreChange, sourceSlots, sourceComputeds) {
|
|
75
75
|
this.version++;
|
|
76
|
-
return import_core.OIMEffectService.INSTANCE.subscribeEffect(channelMap,
|
|
76
|
+
return import_core.OIMEffectService.INSTANCE.subscribeEffect(channelMap, () => {
|
|
77
77
|
this.version++;
|
|
78
78
|
onStoreChange();
|
|
79
|
-
});
|
|
79
|
+
}, sourceSlots, sourceComputeds);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
@@ -96,9 +96,9 @@ function useOIMValue(binding) {
|
|
|
96
96
|
snapshotVersion,
|
|
97
97
|
subscribe: (onStoreChange) => snapshotVersion.subscribeEffect(
|
|
98
98
|
db,
|
|
99
|
+
onStoreChange,
|
|
99
100
|
binding.sourceSlots ?? import_core2.OIM_FROZEN_EMPTY_SLOTS,
|
|
100
|
-
sourceComputeds
|
|
101
|
-
onStoreChange
|
|
101
|
+
sourceComputeds
|
|
102
102
|
)
|
|
103
103
|
};
|
|
104
104
|
}, [db, binding, sourceComputeds]);
|
|
@@ -123,13 +123,23 @@ var import_core3 = require("@oimdb/core");
|
|
|
123
123
|
|
|
124
124
|
// src/oimAssertOneChannel.ts
|
|
125
125
|
function oimAssertOneChannel(channelMap, slot, door) {
|
|
126
|
-
|
|
127
|
-
if (storeSlot === void 0 || storeSlot.channelSlot === channelMap.defaultChannelSlot) return;
|
|
126
|
+
if (slot.storeSlot.channelSlot === channelMap.defaultChannelSlot) return;
|
|
128
127
|
throw new Error(
|
|
129
128
|
`${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.`
|
|
130
129
|
);
|
|
131
130
|
}
|
|
132
131
|
|
|
132
|
+
// src/oimSubscribeHeldSlot.ts
|
|
133
|
+
function oimSubscribeHeldSlot(channelMap, hookName, snapshotVersion, holdingSlot, sourcesOfSlot, onStoreChange) {
|
|
134
|
+
try {
|
|
135
|
+
oimAssertOneChannel(channelMap, holdingSlot, hookName);
|
|
136
|
+
const [sourceSlots, sourceComputeds] = sourcesOfSlot(holdingSlot);
|
|
137
|
+
return snapshotVersion.subscribeEffect(channelMap, onStoreChange, sourceSlots, sourceComputeds);
|
|
138
|
+
} finally {
|
|
139
|
+
holdingSlot.owner.unholdSlot(holdingSlot);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
133
143
|
// src/useOIMSlotByKey.ts
|
|
134
144
|
var sourcesOfRootSlot = (rootSlot) => [[rootSlot], import_core3.OIM_FROZEN_EMPTY_SLOTS];
|
|
135
145
|
function useOIMSlotByKey(hookName, slotCollectionService, storeSlot, key, sourcesOfSlot = sourcesOfRootSlot) {
|
|
@@ -150,18 +160,12 @@ function useOIMSlotByKey(hookName, slotCollectionService, storeSlot, key, source
|
|
|
150
160
|
snapshotVersion,
|
|
151
161
|
subscribe: (onStoreChange) => {
|
|
152
162
|
const holdingSlot = slotCollectionService.holdSlotByKey(storeSlot, settledKey);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
subscribedSlot = void 0;
|
|
160
|
-
disposeEffect();
|
|
161
|
-
};
|
|
162
|
-
} finally {
|
|
163
|
-
holdingSlot.owner.unholdSlot(holdingSlot);
|
|
164
|
-
}
|
|
163
|
+
const effectDisposer = oimSubscribeHeldSlot(db, hookName, snapshotVersion, holdingSlot, sourcesOfSlot, onStoreChange);
|
|
164
|
+
subscribedSlot = holdingSlot;
|
|
165
|
+
return () => {
|
|
166
|
+
subscribedSlot = void 0;
|
|
167
|
+
effectDisposer();
|
|
168
|
+
};
|
|
165
169
|
},
|
|
166
170
|
getSlot: () => subscribedSlot ?? slotCollectionService.getSlotByKey(storeSlot, settledKey)
|
|
167
171
|
};
|
|
@@ -177,7 +181,9 @@ function useOIMEntity(entityCollectionService, entityStoreSlot, key) {
|
|
|
177
181
|
|
|
178
182
|
// src/useOIMSingleSlot.ts
|
|
179
183
|
var import_react7 = require("react");
|
|
180
|
-
|
|
184
|
+
var import_core4 = require("@oimdb/core");
|
|
185
|
+
var sourcesOfRootSlot2 = (rootSlot) => [[rootSlot], import_core4.OIM_FROZEN_EMPTY_SLOTS];
|
|
186
|
+
function useOIMSingleSlot(hookName, singleSlotService, singleSlotStoreSlot, sourcesOfSlot = sourcesOfRootSlot2) {
|
|
181
187
|
const db = useOIMDB();
|
|
182
188
|
const store = (0, import_react7.useMemo)(() => {
|
|
183
189
|
const snapshotVersion = new OIMSnapshotVersion();
|
|
@@ -186,21 +192,16 @@ function useOIMSingleSlot(hookName, singleSlotService, singleSlotStoreSlot) {
|
|
|
186
192
|
snapshotVersion,
|
|
187
193
|
subscribe: (onStoreChange) => {
|
|
188
194
|
const holdingSlot = singleSlotService.holdSingleSlot(singleSlotStoreSlot);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
subscribedSlot =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
disposeEffect();
|
|
196
|
-
};
|
|
197
|
-
} finally {
|
|
198
|
-
holdingSlot.owner.unholdSlot(holdingSlot);
|
|
199
|
-
}
|
|
195
|
+
const effectDisposer = oimSubscribeHeldSlot(db, hookName, snapshotVersion, holdingSlot, sourcesOfSlot, onStoreChange);
|
|
196
|
+
subscribedSlot = holdingSlot;
|
|
197
|
+
return () => {
|
|
198
|
+
subscribedSlot = void 0;
|
|
199
|
+
effectDisposer();
|
|
200
|
+
};
|
|
200
201
|
},
|
|
201
202
|
getSlot: () => subscribedSlot ?? singleSlotService.getSingleSlot(singleSlotStoreSlot)
|
|
202
203
|
};
|
|
203
|
-
}, [hookName, db, singleSlotService, singleSlotStoreSlot]);
|
|
204
|
+
}, [hookName, db, singleSlotService, singleSlotStoreSlot, sourcesOfSlot]);
|
|
204
205
|
useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
|
|
205
206
|
return store.getSlot();
|
|
206
207
|
}
|
|
@@ -220,11 +221,11 @@ function useOIMSingleBucketSlots(singleSlotService, singleSlotStoreSlot) {
|
|
|
220
221
|
var import_react8 = require("react");
|
|
221
222
|
|
|
222
223
|
// src/holdWhileSubscribed.ts
|
|
223
|
-
var
|
|
224
|
+
var import_core5 = require("@oimdb/core");
|
|
224
225
|
function holdWhileSubscribed(slots, subscribe) {
|
|
225
|
-
(0,
|
|
226
|
+
(0, import_core5.oimHoldSlots)(slots);
|
|
226
227
|
const giveEveryHoldBack = () => {
|
|
227
|
-
(0,
|
|
228
|
+
(0, import_core5.oimUnholdSlotsIfAlive)(slots);
|
|
228
229
|
};
|
|
229
230
|
let disposer;
|
|
230
231
|
try {
|
|
@@ -253,9 +254,8 @@ function useOIMField(entityCollectionService, slot, name) {
|
|
|
253
254
|
snapshotVersion,
|
|
254
255
|
subscribe: (onStoreChange) => holdWhileSubscribed(holds, () => snapshotVersion.subscribeEffect(
|
|
255
256
|
db,
|
|
256
|
-
|
|
257
|
-
[]
|
|
258
|
-
onStoreChange
|
|
257
|
+
onStoreChange,
|
|
258
|
+
[entityCollectionService.columnSlotService.getColumn(slot, name)]
|
|
259
259
|
))
|
|
260
260
|
};
|
|
261
261
|
}, [db, entityCollectionService, slot, name]);
|
|
@@ -287,11 +287,11 @@ function useOIMBucketSlotsByKey(bucketCollectionService, bucketStoreSlot, key) {
|
|
|
287
287
|
|
|
288
288
|
// src/useOIMSlotsByKeys.ts
|
|
289
289
|
var import_react10 = require("react");
|
|
290
|
-
var
|
|
290
|
+
var import_core6 = require("@oimdb/core");
|
|
291
291
|
function useOIMSlotsByKeys(slotCollectionService, storeSlot, keys) {
|
|
292
292
|
const settledKeys = (0, import_react10.useRef)(keys);
|
|
293
293
|
const previousKeys = settledKeys.current;
|
|
294
|
-
if (!(0,
|
|
294
|
+
if (!(0, import_core6.oimSameKeySequence)(previousKeys, keys)) settledKeys.current = keys;
|
|
295
295
|
const keysToHold = settledKeys.current;
|
|
296
296
|
const [, resolveAgain] = (0, import_react10.useState)(0);
|
|
297
297
|
const resolvedSlots = (0, import_react10.useRef)(void 0);
|
|
@@ -333,8 +333,8 @@ function useOIMSlotsByKeys(slotCollectionService, storeSlot, keys) {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
// src/useOIMComputedValueByKey.ts
|
|
336
|
-
var
|
|
337
|
-
var sourcesOfComputedSlot = (computedSlot) => [
|
|
336
|
+
var import_core7 = require("@oimdb/core");
|
|
337
|
+
var sourcesOfComputedSlot = (computedSlot) => [import_core7.OIM_FROZEN_EMPTY_SLOTS, [computedSlot]];
|
|
338
338
|
function useOIMComputedValueByKey(computedCollectionService, computedStoreSlot, key) {
|
|
339
339
|
const computedSlot = useOIMSlotByKey(
|
|
340
340
|
"useOIMComputedValueByKey",
|
|
@@ -348,6 +348,8 @@ function useOIMComputedValueByKey(computedCollectionService, computedStoreSlot,
|
|
|
348
348
|
|
|
349
349
|
// src/useOIMSingleComputedValue.ts
|
|
350
350
|
var import_react11 = require("react");
|
|
351
|
+
var import_core8 = require("@oimdb/core");
|
|
352
|
+
var sourcesOfComputedSlot2 = (computedSlot) => [import_core8.OIM_FROZEN_EMPTY_SLOTS, [computedSlot]];
|
|
351
353
|
function useOIMSingleComputedValue(computedService, derive, createSources, dependencyList) {
|
|
352
354
|
const db = useOIMDB();
|
|
353
355
|
const computedStoreSlot = (0, import_react11.useMemo)(
|
|
@@ -355,11 +357,13 @@ function useOIMSingleComputedValue(computedService, derive, createSources, depen
|
|
|
355
357
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- the caller's list is checked at the call site
|
|
356
358
|
[db, computedService, ...dependencyList]
|
|
357
359
|
);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
+
const computedSlot = useOIMSingleSlot(
|
|
361
|
+
"useOIMSingleComputedValue",
|
|
362
|
+
computedService.computedSingleSlotService,
|
|
360
363
|
computedStoreSlot,
|
|
361
|
-
|
|
364
|
+
sourcesOfComputedSlot2
|
|
362
365
|
);
|
|
366
|
+
return computedSlot.computedValueService.getValueForSlot(computedSlot);
|
|
363
367
|
}
|
|
364
368
|
|
|
365
369
|
// src/useOIMComputedCollection.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DependencyList } from 'react';
|
|
3
|
-
import { OIMDB, TOIMSlot,
|
|
3
|
+
import { OIMDB, TOIMSlot, TOIMComputedContentSlot, TOIMStoreKey, OIMSlotCollectionService, TOIMEntitySlot, TOIMStoreSlot, OIMSingleSlotService, TOIMEntityContentSlot, TOIMSingleSlotStore, TOIMBucketContentSlot, OIMSlotContentBucketService, TOIMEntityColumnName, OIMColumnSlotService, TOIMColumnSlot, OIMColumnSlotOwner, TOIMEntityColumnValue, TOIMBucketSlot, TOIMIndexableSlot, TOIMComputedSlot, OIMSingleComputedService, TOIMComputedSources, OIMComputedService, TOIMComputedStoreSlot } from '@oimdb/core';
|
|
4
4
|
|
|
5
5
|
declare const OIMDBContext: React.Context<OIMDB | undefined>;
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ declare function useOIMDB(): OIMDB;
|
|
|
13
13
|
|
|
14
14
|
type TOIMBinding<TValue> = {
|
|
15
15
|
readonly sourceSlots?: readonly TOIMSlot[] | undefined;
|
|
16
|
-
readonly sourceComputeds?: readonly
|
|
16
|
+
readonly sourceComputeds?: readonly TOIMComputedContentSlot[] | undefined;
|
|
17
17
|
readonly derive: () => TValue;
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -26,32 +26,36 @@ type TOIMBinding<TValue> = {
|
|
|
26
26
|
*/
|
|
27
27
|
declare function useOIMValue<TValue>(binding: TOIMBinding<TValue>): TValue;
|
|
28
28
|
|
|
29
|
-
declare function useOIMComputedValue<TValue>(computedSlot:
|
|
29
|
+
declare function useOIMComputedValue<TValue>(computedSlot: TOIMComputedContentSlot<TValue>): TValue;
|
|
30
30
|
|
|
31
|
-
declare function useOIMEntity<TEntity extends object, TKey = TOIMStoreKey, TStore = unknown>(entityCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMEntitySlot<TEntity, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, entityStoreSlot: TOIMStoreSlot<TStore, TOIMEntitySlot<TEntity, TKey>>, key: TKey): TEntity | undefined;
|
|
31
|
+
declare function useOIMEntity<TEntity extends object, TKey extends NonNullable<unknown> = TOIMStoreKey, TStore = unknown>(entityCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMEntitySlot<TEntity, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, entityStoreSlot: TOIMStoreSlot<TStore, TOIMEntitySlot<TEntity, TKey>>, key: TKey): TEntity | undefined;
|
|
32
32
|
|
|
33
|
-
declare function useOIMSingleEntity<TEntity extends object>(singleSlotService: Pick<OIMSingleSlotService<
|
|
33
|
+
declare function useOIMSingleEntity<TEntity extends object>(singleSlotService: Pick<OIMSingleSlotService<TOIMEntityContentSlot<TEntity>, unknown>, 'getSingleSlot' | 'holdSingleSlot'>, singleSlotStoreSlot: TOIMStoreSlot<TOIMSingleSlotStore<TOIMEntityContentSlot<TEntity>>, TOIMEntityContentSlot<TEntity>>): TEntity | undefined;
|
|
34
34
|
|
|
35
|
-
declare function useOIMSingleBucketSlots<TEntity extends object, TSlots = unknown>(singleSlotService: Pick<OIMSingleSlotService<
|
|
35
|
+
declare function useOIMSingleBucketSlots<TEntity extends object, TSlots = unknown>(singleSlotService: Pick<OIMSingleSlotService<TOIMBucketContentSlot<TSlots>, Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>>, 'getSingleSlot' | 'holdSingleSlot' | 'slotContentService'>, singleSlotStoreSlot: TOIMStoreSlot<TOIMSingleSlotStore<TOIMBucketContentSlot<TSlots>>, TOIMBucketContentSlot<TSlots>>): readonly TOIMEntitySlot<TEntity>[];
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* One field of one identity. It cannot go through {@link useOIMValue}: a column identity is
|
|
39
39
|
* minted INSIDE the subscription, so there is no root slot a binding could name. `slot` is an
|
|
40
40
|
* ENTITY SLOT because an entity slot is what can be taken out from under this component — ../README.md.
|
|
41
41
|
*/
|
|
42
|
-
declare function useOIMField<TEntity extends object, TName extends TOIMEntityColumnName<TEntity>, TKey = TOIMStoreKey>(entityCollectionService:
|
|
42
|
+
declare function useOIMField<TEntity extends object, TName extends TOIMEntityColumnName<TEntity>, TKey extends NonNullable<unknown> = TOIMStoreKey>(entityCollectionService: {
|
|
43
|
+
readonly columnSlotService: Pick<OIMColumnSlotService<TOIMEntitySlot<TEntity, TKey>, TName, TOIMColumnSlot, OIMColumnSlotOwner<TOIMSlot, TOIMColumnSlot>>, 'getColumn'>;
|
|
44
|
+
}, slot: TOIMEntitySlot<TEntity, TKey>, name: TName): TOIMEntityColumnValue<TEntity, TName> | undefined;
|
|
43
45
|
|
|
44
46
|
/** A bucket's slots, copied out of the service's LIVE container, in the collection's order. */
|
|
45
|
-
declare function useOIMBucketSlots<TEntity extends object, TSlots = unknown>(bucketCollectionService:
|
|
47
|
+
declare function useOIMBucketSlots<TEntity extends object, TSlots = unknown>(bucketCollectionService: {
|
|
48
|
+
readonly slotContentService: Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>;
|
|
49
|
+
}, bucketSlot: TOIMBucketContentSlot<TSlots>): readonly TOIMEntitySlot<TEntity>[];
|
|
46
50
|
|
|
47
|
-
declare function useOIMBucketSlotsByKey<TEntity extends object, TSlots = unknown, TKey = TOIMStoreKey, TStore = unknown>(bucketCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore, Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>>, 'getSlotByKey' | 'holdSlotByKey' | 'slotContentService'>, bucketStoreSlot: TOIMStoreSlot<TStore, TOIMBucketSlot<TSlots, TKey>>, key: TKey): readonly TOIMEntitySlot<TEntity>[];
|
|
51
|
+
declare function useOIMBucketSlotsByKey<TEntity extends object, TSlots = unknown, TKey extends NonNullable<unknown> = TOIMStoreKey, TStore = unknown>(bucketCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore, Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>>, 'getSlotByKey' | 'holdSlotByKey' | 'slotContentService'>, bucketStoreSlot: TOIMStoreSlot<TStore, TOIMBucketSlot<TSlots, TKey>>, key: TKey): readonly TOIMEntitySlot<TEntity>[];
|
|
48
52
|
|
|
49
|
-
declare function useOIMSlotsByKeys<TKey
|
|
53
|
+
declare function useOIMSlotsByKeys<TKey extends NonNullable<unknown>, TSlot extends TOIMIndexableSlot<TKey>, TStore = unknown>(slotCollectionService: Pick<OIMSlotCollectionService<TKey, TSlot, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, storeSlot: TOIMStoreSlot<TStore, TSlot>, keys: readonly TKey[]): readonly TSlot[];
|
|
50
54
|
|
|
51
|
-
declare function useOIMComputedValueByKey<TValue, TKey = TOIMStoreKey, TStore = unknown>(computedCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMComputedSlot<TValue, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, computedStoreSlot: TOIMStoreSlot<TStore, TOIMComputedSlot<TValue, TKey>>, key: TKey): TValue;
|
|
55
|
+
declare function useOIMComputedValueByKey<TValue, TKey extends NonNullable<unknown> = TOIMStoreKey, TStore = unknown>(computedCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMComputedSlot<TValue, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, computedStoreSlot: TOIMStoreSlot<TStore, TOIMComputedSlot<TValue, TKey>>, key: TKey): TValue;
|
|
52
56
|
|
|
53
|
-
declare function useOIMSingleComputedValue<TValue>(computedService:
|
|
57
|
+
declare function useOIMSingleComputedValue<TValue>(computedService: OIMSingleComputedService<TValue>, derive: ((computedSlot: TOIMComputedContentSlot<TValue>) => TValue) | undefined, createSources: ((computedSlot: TOIMComputedContentSlot<TValue>) => Partial<TOIMComputedSources>) | undefined, dependencyList: DependencyList): TValue;
|
|
54
58
|
|
|
55
|
-
declare function useOIMComputedCollection<TKey
|
|
59
|
+
declare function useOIMComputedCollection<TKey extends NonNullable<unknown>, TValue, TStore>(computedService: OIMComputedService<TKey, TValue, TStore>, derive: ((computedSlot: TOIMComputedSlot<TValue, TKey>) => TValue) | undefined, createSources: ((computedSlot: TOIMComputedSlot<TValue, TKey>) => Partial<TOIMComputedSources>) | undefined, dependencyList: DependencyList): TOIMComputedStoreSlot<TStore, TValue, TOIMComputedSlot<TValue, TKey>>;
|
|
56
60
|
|
|
57
61
|
export { OIMDBContext, OIMDBProvider, type TOIMBinding, useOIMBucketSlots, useOIMBucketSlotsByKey, useOIMComputedCollection, useOIMComputedValue, useOIMComputedValueByKey, useOIMDB, useOIMEntity, useOIMField, useOIMSingleBucketSlots, useOIMSingleComputedValue, useOIMSingleEntity, useOIMSlotsByKeys, useOIMValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DependencyList } from 'react';
|
|
3
|
-
import { OIMDB, TOIMSlot,
|
|
3
|
+
import { OIMDB, TOIMSlot, TOIMComputedContentSlot, TOIMStoreKey, OIMSlotCollectionService, TOIMEntitySlot, TOIMStoreSlot, OIMSingleSlotService, TOIMEntityContentSlot, TOIMSingleSlotStore, TOIMBucketContentSlot, OIMSlotContentBucketService, TOIMEntityColumnName, OIMColumnSlotService, TOIMColumnSlot, OIMColumnSlotOwner, TOIMEntityColumnValue, TOIMBucketSlot, TOIMIndexableSlot, TOIMComputedSlot, OIMSingleComputedService, TOIMComputedSources, OIMComputedService, TOIMComputedStoreSlot } from '@oimdb/core';
|
|
4
4
|
|
|
5
5
|
declare const OIMDBContext: React.Context<OIMDB | undefined>;
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ declare function useOIMDB(): OIMDB;
|
|
|
13
13
|
|
|
14
14
|
type TOIMBinding<TValue> = {
|
|
15
15
|
readonly sourceSlots?: readonly TOIMSlot[] | undefined;
|
|
16
|
-
readonly sourceComputeds?: readonly
|
|
16
|
+
readonly sourceComputeds?: readonly TOIMComputedContentSlot[] | undefined;
|
|
17
17
|
readonly derive: () => TValue;
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -26,32 +26,36 @@ type TOIMBinding<TValue> = {
|
|
|
26
26
|
*/
|
|
27
27
|
declare function useOIMValue<TValue>(binding: TOIMBinding<TValue>): TValue;
|
|
28
28
|
|
|
29
|
-
declare function useOIMComputedValue<TValue>(computedSlot:
|
|
29
|
+
declare function useOIMComputedValue<TValue>(computedSlot: TOIMComputedContentSlot<TValue>): TValue;
|
|
30
30
|
|
|
31
|
-
declare function useOIMEntity<TEntity extends object, TKey = TOIMStoreKey, TStore = unknown>(entityCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMEntitySlot<TEntity, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, entityStoreSlot: TOIMStoreSlot<TStore, TOIMEntitySlot<TEntity, TKey>>, key: TKey): TEntity | undefined;
|
|
31
|
+
declare function useOIMEntity<TEntity extends object, TKey extends NonNullable<unknown> = TOIMStoreKey, TStore = unknown>(entityCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMEntitySlot<TEntity, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, entityStoreSlot: TOIMStoreSlot<TStore, TOIMEntitySlot<TEntity, TKey>>, key: TKey): TEntity | undefined;
|
|
32
32
|
|
|
33
|
-
declare function useOIMSingleEntity<TEntity extends object>(singleSlotService: Pick<OIMSingleSlotService<
|
|
33
|
+
declare function useOIMSingleEntity<TEntity extends object>(singleSlotService: Pick<OIMSingleSlotService<TOIMEntityContentSlot<TEntity>, unknown>, 'getSingleSlot' | 'holdSingleSlot'>, singleSlotStoreSlot: TOIMStoreSlot<TOIMSingleSlotStore<TOIMEntityContentSlot<TEntity>>, TOIMEntityContentSlot<TEntity>>): TEntity | undefined;
|
|
34
34
|
|
|
35
|
-
declare function useOIMSingleBucketSlots<TEntity extends object, TSlots = unknown>(singleSlotService: Pick<OIMSingleSlotService<
|
|
35
|
+
declare function useOIMSingleBucketSlots<TEntity extends object, TSlots = unknown>(singleSlotService: Pick<OIMSingleSlotService<TOIMBucketContentSlot<TSlots>, Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>>, 'getSingleSlot' | 'holdSingleSlot' | 'slotContentService'>, singleSlotStoreSlot: TOIMStoreSlot<TOIMSingleSlotStore<TOIMBucketContentSlot<TSlots>>, TOIMBucketContentSlot<TSlots>>): readonly TOIMEntitySlot<TEntity>[];
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* One field of one identity. It cannot go through {@link useOIMValue}: a column identity is
|
|
39
39
|
* minted INSIDE the subscription, so there is no root slot a binding could name. `slot` is an
|
|
40
40
|
* ENTITY SLOT because an entity slot is what can be taken out from under this component — ../README.md.
|
|
41
41
|
*/
|
|
42
|
-
declare function useOIMField<TEntity extends object, TName extends TOIMEntityColumnName<TEntity>, TKey = TOIMStoreKey>(entityCollectionService:
|
|
42
|
+
declare function useOIMField<TEntity extends object, TName extends TOIMEntityColumnName<TEntity>, TKey extends NonNullable<unknown> = TOIMStoreKey>(entityCollectionService: {
|
|
43
|
+
readonly columnSlotService: Pick<OIMColumnSlotService<TOIMEntitySlot<TEntity, TKey>, TName, TOIMColumnSlot, OIMColumnSlotOwner<TOIMSlot, TOIMColumnSlot>>, 'getColumn'>;
|
|
44
|
+
}, slot: TOIMEntitySlot<TEntity, TKey>, name: TName): TOIMEntityColumnValue<TEntity, TName> | undefined;
|
|
43
45
|
|
|
44
46
|
/** A bucket's slots, copied out of the service's LIVE container, in the collection's order. */
|
|
45
|
-
declare function useOIMBucketSlots<TEntity extends object, TSlots = unknown>(bucketCollectionService:
|
|
47
|
+
declare function useOIMBucketSlots<TEntity extends object, TSlots = unknown>(bucketCollectionService: {
|
|
48
|
+
readonly slotContentService: Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>;
|
|
49
|
+
}, bucketSlot: TOIMBucketContentSlot<TSlots>): readonly TOIMEntitySlot<TEntity>[];
|
|
46
50
|
|
|
47
|
-
declare function useOIMBucketSlotsByKey<TEntity extends object, TSlots = unknown, TKey = TOIMStoreKey, TStore = unknown>(bucketCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore, Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>>, 'getSlotByKey' | 'holdSlotByKey' | 'slotContentService'>, bucketStoreSlot: TOIMStoreSlot<TStore, TOIMBucketSlot<TSlots, TKey>>, key: TKey): readonly TOIMEntitySlot<TEntity>[];
|
|
51
|
+
declare function useOIMBucketSlotsByKey<TEntity extends object, TSlots = unknown, TKey extends NonNullable<unknown> = TOIMStoreKey, TStore = unknown>(bucketCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore, Pick<OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>, 'getBucketMemberSlots'>>, 'getSlotByKey' | 'holdSlotByKey' | 'slotContentService'>, bucketStoreSlot: TOIMStoreSlot<TStore, TOIMBucketSlot<TSlots, TKey>>, key: TKey): readonly TOIMEntitySlot<TEntity>[];
|
|
48
52
|
|
|
49
|
-
declare function useOIMSlotsByKeys<TKey
|
|
53
|
+
declare function useOIMSlotsByKeys<TKey extends NonNullable<unknown>, TSlot extends TOIMIndexableSlot<TKey>, TStore = unknown>(slotCollectionService: Pick<OIMSlotCollectionService<TKey, TSlot, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, storeSlot: TOIMStoreSlot<TStore, TSlot>, keys: readonly TKey[]): readonly TSlot[];
|
|
50
54
|
|
|
51
|
-
declare function useOIMComputedValueByKey<TValue, TKey = TOIMStoreKey, TStore = unknown>(computedCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMComputedSlot<TValue, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, computedStoreSlot: TOIMStoreSlot<TStore, TOIMComputedSlot<TValue, TKey>>, key: TKey): TValue;
|
|
55
|
+
declare function useOIMComputedValueByKey<TValue, TKey extends NonNullable<unknown> = TOIMStoreKey, TStore = unknown>(computedCollectionService: Pick<OIMSlotCollectionService<TKey, TOIMComputedSlot<TValue, TKey>, TStore, unknown>, 'getSlotByKey' | 'holdSlotByKey'>, computedStoreSlot: TOIMStoreSlot<TStore, TOIMComputedSlot<TValue, TKey>>, key: TKey): TValue;
|
|
52
56
|
|
|
53
|
-
declare function useOIMSingleComputedValue<TValue>(computedService:
|
|
57
|
+
declare function useOIMSingleComputedValue<TValue>(computedService: OIMSingleComputedService<TValue>, derive: ((computedSlot: TOIMComputedContentSlot<TValue>) => TValue) | undefined, createSources: ((computedSlot: TOIMComputedContentSlot<TValue>) => Partial<TOIMComputedSources>) | undefined, dependencyList: DependencyList): TValue;
|
|
54
58
|
|
|
55
|
-
declare function useOIMComputedCollection<TKey
|
|
59
|
+
declare function useOIMComputedCollection<TKey extends NonNullable<unknown>, TValue, TStore>(computedService: OIMComputedService<TKey, TValue, TStore>, derive: ((computedSlot: TOIMComputedSlot<TValue, TKey>) => TValue) | undefined, createSources: ((computedSlot: TOIMComputedSlot<TValue, TKey>) => Partial<TOIMComputedSources>) | undefined, dependencyList: DependencyList): TOIMComputedStoreSlot<TStore, TValue, TOIMComputedSlot<TValue, TKey>>;
|
|
56
60
|
|
|
57
61
|
export { OIMDBContext, OIMDBProvider, type TOIMBinding, useOIMBucketSlots, useOIMBucketSlotsByKey, useOIMComputedCollection, useOIMComputedValue, useOIMComputedValueByKey, useOIMDB, useOIMEntity, useOIMField, useOIMSingleBucketSlots, useOIMSingleComputedValue, useOIMSingleEntity, useOIMSlotsByKeys, useOIMValue };
|