atom.io 0.14.8 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/data/dist/index.cjs +216 -218
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +30 -11
- package/data/dist/index.js +218 -221
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +337 -296
- package/data/src/struct-family.ts +2 -2
- package/data/src/struct.ts +2 -2
- package/dist/chunk-S7R5MU6A.js +137 -0
- package/dist/chunk-S7R5MU6A.js.map +1 -0
- package/dist/index.cjs +3 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1 -151
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +278 -201
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +43 -36
- package/internal/dist/index.js +224 -194
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-atom.ts +5 -86
- package/internal/src/atom/create-regular-atom.ts +92 -0
- package/internal/src/atom/index.ts +16 -0
- package/internal/src/atom/is-default.ts +0 -5
- package/internal/src/caching.ts +14 -16
- package/internal/src/families/create-atom-family.ts +20 -46
- package/internal/src/families/create-readonly-selector-family.ts +4 -1
- package/internal/src/families/create-regular-atom-family.ts +72 -0
- package/internal/src/families/create-selector-family.ts +2 -0
- package/internal/src/families/index.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/create-mutable-atom.ts +8 -3
- package/internal/src/mutable/get-update-family.ts +1 -1
- package/internal/src/mutable/is-mutable.ts +3 -30
- package/internal/src/mutable/tracker-family.ts +2 -2
- package/internal/src/mutable/tracker.ts +5 -5
- package/internal/src/operation.ts +14 -18
- package/internal/src/selector/create-read-write-selector.ts +2 -3
- package/internal/src/selector/create-selector.ts +1 -1
- package/internal/src/selector/register-selector.ts +9 -14
- package/internal/src/set-state/evict-downstream.ts +3 -5
- package/internal/src/set-state/set-atom.ts +14 -17
- package/internal/src/store/store.ts +23 -19
- package/internal/src/store/withdraw.ts +32 -70
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +5 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -3
- package/internal/src/transaction/apply-transaction.ts +20 -2
- package/internal/src/transaction/build-transaction.ts +19 -11
- package/internal/src/transaction/create-transaction.ts +6 -11
- package/internal/src/transaction/index.ts +2 -3
- package/introspection/dist/index.cjs +6 -6
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js +7 -7
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +7 -2
- package/introspection/src/attach-selector-index.ts +7 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-timeline-index.ts +2 -2
- package/introspection/src/attach-transaction-index.ts +2 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/package.json +10 -8
- package/react-devtools/dist/index.d.ts +17 -11
- package/realtime-client/dist/index.cjs +3 -0
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +3 -3
- package/realtime-client/dist/index.js +3 -0
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +6 -6
- package/realtime-client/src/{use-pull-family-member.ts → pull-family-member.ts} +1 -1
- package/realtime-client/src/{use-pull-mutable-family-member.ts → pull-mutable-family-member.ts} +1 -1
- package/realtime-client/src/{use-pull-mutable.ts → pull-mutable.ts} +1 -1
- package/realtime-client/src/{use-server-action.ts → server-action.ts} +3 -0
- package/realtime-react/dist/index.cjs +31 -17
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +3 -3
- package/realtime-react/dist/index.js +31 -17
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/realtime-context.tsx +2 -3
- package/realtime-react/src/use-pull-family-member.ts +6 -2
- package/realtime-react/src/use-pull-mutable-family-member.ts +5 -4
- package/realtime-react/src/use-pull-mutable.ts +6 -2
- package/realtime-react/src/use-pull.ts +5 -1
- package/realtime-react/src/use-push.ts +5 -4
- package/realtime-react/src/use-server-action.ts +5 -4
- package/src/atom.ts +8 -17
- package/src/selector.ts +3 -1
- package/src/set-state.ts +1 -3
- package/src/silo.ts +2 -14
- package/src/transaction.ts +17 -6
- package/transceivers/set-rtx/dist/index.cjs +2 -1
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.js +2 -1
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/src/set-rtx.ts +2 -1
- package/internal/src/transaction/redo-transaction.ts +0 -27
- package/internal/src/transaction/undo-transaction.ts +0 -27
- /package/realtime-client/src/{use-pull.ts → pull.ts} +0 -0
- /package/realtime-client/src/{use-push.ts → push.ts} +0 -0
package/README.md
CHANGED
|
@@ -49,8 +49,13 @@ bun i atom.io
|
|
|
49
49
|
<a aria-label="NPM version" href="https://www.npmjs.com/package/atom.io">
|
|
50
50
|
<img alt="NPM Version" src="https://img.shields.io/npm/v/atom.io?style=for-the-badge&labelColor=333">
|
|
51
51
|
</a>
|
|
52
|
+
<a aria-label="Coverage" href="https://coveralls.io/github/jeremybanka/wayforge">
|
|
53
|
+
<img alt="Coverage" src="https://img.shields.io/coverallsCoverage/github/jeremybanka/wayforge?style=for-the-badge&labelColor=333">
|
|
54
|
+
</a>
|
|
55
|
+
|
|
52
56
|
</p>
|
|
53
57
|
|
|
54
58
|
|
|
55
59
|
|
|
56
60
|
|
|
61
|
+
|
package/data/dist/index.cjs
CHANGED
|
@@ -285,263 +285,260 @@ var TRANSACTORS = { get: atom_io.getState, set: atom_io.setState };
|
|
|
285
285
|
function capitalize(string) {
|
|
286
286
|
return string[0].toUpperCase() + string.slice(1);
|
|
287
287
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
288
|
+
var Join = class {
|
|
289
|
+
constructor(options, defaultContent, store = internal.IMPLICIT.STORE) {
|
|
290
|
+
this.transactors = TRANSACTORS;
|
|
291
|
+
const a = options.between[0];
|
|
292
|
+
const b = options.between[1];
|
|
293
|
+
const findRelatedKeysState = internal.createMutableAtomFamily(
|
|
294
|
+
{
|
|
295
|
+
key: `${options.key}/relatedKeys`,
|
|
296
|
+
default: () => new setRtx.SetRTX(),
|
|
297
|
+
mutable: true,
|
|
298
|
+
fromJson: (json) => setRtx.SetRTX.fromJSON(json),
|
|
299
|
+
toJson: (set) => set.toJSON()
|
|
300
|
+
},
|
|
301
|
+
store
|
|
302
|
+
);
|
|
303
|
+
this.core = { findRelatedKeysState };
|
|
304
|
+
const getRelatedKeys = ({ get }, key) => get(findRelatedKeysState(key));
|
|
305
|
+
const addRelation = (transactors, a2, b2) => {
|
|
306
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
307
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
306
308
|
transactors.set(findRelatedKeysState(a2), aKeys.add(b2));
|
|
307
|
-
} else {
|
|
308
|
-
transactors.set(findRelatedKeysState(a2), new setRtx.SetRTX([b2]));
|
|
309
|
-
}
|
|
310
|
-
if (bKeys) {
|
|
311
309
|
transactors.set(findRelatedKeysState(b2), bKeys.add(a2));
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
};
|
|
316
|
-
const deleteRelation = (transactors, a2, b2) => {
|
|
317
|
-
const aKeys = getRelatedKeys(transactors, a2);
|
|
318
|
-
if (aKeys) {
|
|
310
|
+
};
|
|
311
|
+
const deleteRelation = (transactors, a2, b2) => {
|
|
312
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
319
313
|
aKeys.delete(b2);
|
|
320
314
|
if (aKeys.size === 0) {
|
|
321
|
-
|
|
315
|
+
atom_io.dispose(findRelatedKeysState(a2));
|
|
322
316
|
}
|
|
323
317
|
const bKeys = getRelatedKeys(transactors, b2);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
transactors.set(findRelatedKeysState(b2), void 0);
|
|
328
|
-
}
|
|
318
|
+
bKeys.delete(a2);
|
|
319
|
+
if (bKeys.size === 0) {
|
|
320
|
+
atom_io.dispose(findRelatedKeysState(b2));
|
|
329
321
|
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const aRelations = getRelatedKeys(transactors, a2);
|
|
334
|
-
if (aRelations) {
|
|
322
|
+
};
|
|
323
|
+
const replaceRelationsSafely = (transactors, a2, bs) => {
|
|
324
|
+
const aRelations = getRelatedKeys(transactors, a2);
|
|
335
325
|
for (const b2 of aRelations) {
|
|
336
326
|
const bKeys = getRelatedKeys(transactors, b2);
|
|
337
327
|
if (bKeys) {
|
|
338
328
|
bKeys.delete(a2);
|
|
339
329
|
if (bKeys.size === 0) {
|
|
340
|
-
|
|
330
|
+
atom_io.dispose(findRelatedKeysState(b2));
|
|
341
331
|
}
|
|
342
332
|
}
|
|
343
333
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const bKeys = getRelatedKeys(transactors, b2);
|
|
348
|
-
if (bKeys) {
|
|
334
|
+
transactors.set(findRelatedKeysState(a2), new setRtx.SetRTX(bs));
|
|
335
|
+
for (const b2 of bs) {
|
|
336
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
349
337
|
bKeys.add(a2);
|
|
350
|
-
} else {
|
|
351
|
-
transactors.set(findRelatedKeysState(b2), new setRtx.SetRTX([a2]));
|
|
352
338
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
let bKeys = getRelatedKeys(transactors, b2);
|
|
359
|
-
if (bKeys) {
|
|
339
|
+
};
|
|
340
|
+
const replaceRelationsUnsafely = (transactors, a2, bs) => {
|
|
341
|
+
transactors.set(findRelatedKeysState(a2), new setRtx.SetRTX(bs));
|
|
342
|
+
for (const b2 of bs) {
|
|
343
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
360
344
|
bKeys.add(a2);
|
|
361
|
-
} else {
|
|
362
|
-
bKeys = new setRtx.SetRTX([a2]);
|
|
363
|
-
transactors.set(findRelatedKeysState(b2), bKeys);
|
|
364
345
|
}
|
|
346
|
+
};
|
|
347
|
+
const has = (transactors, a2, b2) => {
|
|
348
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
349
|
+
return b2 ? aKeys.has(b2) : aKeys.size > 0;
|
|
350
|
+
};
|
|
351
|
+
const baseExternalStoreConfiguration = {
|
|
352
|
+
getRelatedKeys: (key) => getRelatedKeys(this.transactors, key),
|
|
353
|
+
addRelation: (a2, b2) => addRelation(this.transactors, a2, b2),
|
|
354
|
+
deleteRelation: (a2, b2) => deleteRelation(this.transactors, a2, b2),
|
|
355
|
+
replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(this.transactors, a2, bs),
|
|
356
|
+
replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(this.transactors, a2, bs),
|
|
357
|
+
has: (a2, b2) => has(this.transactors, a2, b2)
|
|
358
|
+
};
|
|
359
|
+
let externalStore;
|
|
360
|
+
let findContentState;
|
|
361
|
+
if (defaultContent) {
|
|
362
|
+
findContentState = internal.createRegularAtomFamily(
|
|
363
|
+
{
|
|
364
|
+
key: `${options.key}/content`,
|
|
365
|
+
default: defaultContent
|
|
366
|
+
},
|
|
367
|
+
store
|
|
368
|
+
);
|
|
369
|
+
const getContent = ({ get }, key) => get(findContentState(key));
|
|
370
|
+
const setContent = (transactors, key, content) => transactors.set(findContentState(key), content);
|
|
371
|
+
const deleteContent = (_, key) => atom_io.dispose(findContentState(key));
|
|
372
|
+
const externalStoreWithContentConfiguration = {
|
|
373
|
+
getContent: (contentKey) => {
|
|
374
|
+
const content = getContent(this.transactors, contentKey);
|
|
375
|
+
return content;
|
|
376
|
+
},
|
|
377
|
+
setContent: (contentKey, content) => {
|
|
378
|
+
setContent(this.transactors, contentKey, content);
|
|
379
|
+
},
|
|
380
|
+
deleteContent: (contentKey) => {
|
|
381
|
+
deleteContent(this.transactors, contentKey);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
externalStore = Object.assign(
|
|
385
|
+
baseExternalStoreConfiguration,
|
|
386
|
+
externalStoreWithContentConfiguration
|
|
387
|
+
);
|
|
388
|
+
} else {
|
|
389
|
+
externalStore = baseExternalStoreConfiguration;
|
|
365
390
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
};
|
|
372
|
-
const baseExternalStoreConfiguration = {
|
|
373
|
-
getRelatedKeys: (key) => getRelatedKeys(TRANSACTORS, key),
|
|
374
|
-
addRelation: (a2, b2) => addRelation(TRANSACTORS, a2, b2),
|
|
375
|
-
deleteRelation: (a2, b2) => deleteRelation(TRANSACTORS, a2, b2),
|
|
376
|
-
replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(TRANSACTORS, a2, bs),
|
|
377
|
-
replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(TRANSACTORS, a2, bs),
|
|
378
|
-
has: (a2, b2) => has(TRANSACTORS, a2, b2)
|
|
379
|
-
};
|
|
380
|
-
let externalStore;
|
|
381
|
-
let findContentState;
|
|
382
|
-
if (defaultContent) {
|
|
383
|
-
findContentState = internal.createAtomFamily(
|
|
391
|
+
const relations = new Junction(options, {
|
|
392
|
+
externalStore,
|
|
393
|
+
makeContentKey: (...args) => args.sort().join(`:`)
|
|
394
|
+
});
|
|
395
|
+
const createSingleKeyStateFamily = () => internal.createSelectorFamily(
|
|
384
396
|
{
|
|
385
|
-
key: `${options.key}/
|
|
386
|
-
|
|
397
|
+
key: `${options.key}/singleRelatedKey`,
|
|
398
|
+
get: (key) => ({ get }) => {
|
|
399
|
+
const relatedKeys = get(findRelatedKeysState(key));
|
|
400
|
+
for (const relatedKey of relatedKeys) {
|
|
401
|
+
return relatedKey;
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
387
405
|
},
|
|
388
406
|
store
|
|
389
407
|
);
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
deleteContent(TRANSACTORS, contentKey);
|
|
403
|
-
}
|
|
408
|
+
const getMultipleKeyStateFamily = () => {
|
|
409
|
+
return internal.createSelectorFamily(
|
|
410
|
+
{
|
|
411
|
+
key: `${options.key}/multipleRelatedKeys`,
|
|
412
|
+
get: (key) => ({ get }) => {
|
|
413
|
+
const jsonFamily = internal.getJsonFamily(findRelatedKeysState, store);
|
|
414
|
+
const json = get(jsonFamily(key));
|
|
415
|
+
return json.members;
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
store
|
|
419
|
+
);
|
|
404
420
|
};
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
});
|
|
416
|
-
const createSingleKeyStateFamily = () => internal.createSelectorFamily(
|
|
417
|
-
{
|
|
418
|
-
key: `${options.key}/singleRelatedKey`,
|
|
419
|
-
get: (key) => ({ get }) => {
|
|
420
|
-
const relatedKeys = get(findRelatedKeysState(key));
|
|
421
|
-
for (const relatedKey of relatedKeys) {
|
|
422
|
-
return relatedKey;
|
|
421
|
+
const createSingleEntryStateFamily = () => internal.createSelectorFamily(
|
|
422
|
+
{
|
|
423
|
+
key: `${options.key}/singleRelatedEntry`,
|
|
424
|
+
get: (key) => ({ get }) => {
|
|
425
|
+
const relatedKeys = get(findRelatedKeysState(key));
|
|
426
|
+
for (const relatedKey of relatedKeys) {
|
|
427
|
+
const contentKey = relations.makeContentKey(key, relatedKey);
|
|
428
|
+
return [relatedKey, get(findContentState(contentKey))];
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
423
431
|
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
432
|
+
},
|
|
433
|
+
store
|
|
434
|
+
);
|
|
435
|
+
const getMultipleEntryStateFamily = () => internal.createSelectorFamily(
|
|
436
|
+
{
|
|
437
|
+
key: `${options.key}/multipleRelatedEntries`,
|
|
438
|
+
get: (key) => ({ get }) => {
|
|
439
|
+
const jsonFamily = internal.getJsonFamily(findRelatedKeysState, store);
|
|
440
|
+
const json = get(jsonFamily(key));
|
|
441
|
+
return json.members.map((relatedKey) => {
|
|
442
|
+
const contentKey = relations.makeContentKey(key, relatedKey);
|
|
443
|
+
return [relatedKey, get(findContentState(contentKey))];
|
|
444
|
+
});
|
|
437
445
|
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
return [relatedKey, get(findContentState(contentKey))];
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
store
|
|
454
|
-
);
|
|
455
|
-
switch (options.cardinality) {
|
|
456
|
-
case `1:1`: {
|
|
457
|
-
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
458
|
-
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
459
|
-
const stateKeyB = `${b}KeyOf${capitalize(a)}`;
|
|
460
|
-
const findStateBase = {
|
|
461
|
-
[stateKeyA]: findSingleRelatedKeyState,
|
|
462
|
-
[stateKeyB]: findSingleRelatedKeyState
|
|
463
|
-
};
|
|
464
|
-
let findState;
|
|
465
|
-
if (defaultContent) {
|
|
466
|
-
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
467
|
-
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
468
|
-
const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
|
|
469
|
-
const findStateWithContent = {
|
|
470
|
-
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
471
|
-
[entriesStateKeyB]: findSingleRelatedEntryState
|
|
446
|
+
},
|
|
447
|
+
store
|
|
448
|
+
);
|
|
449
|
+
switch (options.cardinality) {
|
|
450
|
+
case `1:1`: {
|
|
451
|
+
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
452
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
453
|
+
const stateKeyB = `${b}KeyOf${capitalize(a)}`;
|
|
454
|
+
const findStateBase = {
|
|
455
|
+
[stateKeyA]: findSingleRelatedKeyState,
|
|
456
|
+
[stateKeyB]: findSingleRelatedKeyState
|
|
472
457
|
};
|
|
473
|
-
findState
|
|
474
|
-
|
|
475
|
-
|
|
458
|
+
let findState;
|
|
459
|
+
if (defaultContent) {
|
|
460
|
+
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
461
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
462
|
+
const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
|
|
463
|
+
const findStateWithContent = {
|
|
464
|
+
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
465
|
+
[entriesStateKeyB]: findSingleRelatedEntryState
|
|
466
|
+
};
|
|
467
|
+
findState = Object.assign(findStateBase, findStateWithContent);
|
|
468
|
+
} else {
|
|
469
|
+
findState = findStateBase;
|
|
470
|
+
}
|
|
471
|
+
this.relations = relations;
|
|
472
|
+
this.findState = findState;
|
|
473
|
+
break;
|
|
476
474
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
486
|
-
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
487
|
-
const findStateBase = {
|
|
488
|
-
[stateKeyA]: findSingleRelatedKeyState,
|
|
489
|
-
[stateKeyB]: findMultipleRelatedKeysState
|
|
490
|
-
};
|
|
491
|
-
let findState;
|
|
492
|
-
if (defaultContent) {
|
|
493
|
-
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
494
|
-
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
495
|
-
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
496
|
-
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
497
|
-
const findStateWithContent = {
|
|
498
|
-
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
499
|
-
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
475
|
+
case `1:n`: {
|
|
476
|
+
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
477
|
+
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
478
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
479
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
480
|
+
const findStateBase = {
|
|
481
|
+
[stateKeyA]: findSingleRelatedKeyState,
|
|
482
|
+
[stateKeyB]: findMultipleRelatedKeysState
|
|
500
483
|
};
|
|
501
|
-
findState
|
|
502
|
-
|
|
503
|
-
|
|
484
|
+
let findState;
|
|
485
|
+
if (defaultContent) {
|
|
486
|
+
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
487
|
+
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
488
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
489
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
490
|
+
const findStateWithContent = {
|
|
491
|
+
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
492
|
+
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
493
|
+
};
|
|
494
|
+
findState = Object.assign(findStateBase, findStateWithContent);
|
|
495
|
+
} else {
|
|
496
|
+
findState = findStateBase;
|
|
497
|
+
}
|
|
498
|
+
this.relations = relations;
|
|
499
|
+
this.findState = findState;
|
|
500
|
+
break;
|
|
504
501
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const stateKeyA = `${a}KeysOf${capitalize(b)}`;
|
|
513
|
-
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
514
|
-
const findStateBase = {
|
|
515
|
-
[stateKeyA]: findMultipleRelatedKeysState,
|
|
516
|
-
[stateKeyB]: findMultipleRelatedKeysState
|
|
517
|
-
};
|
|
518
|
-
let findState;
|
|
519
|
-
if (defaultContent) {
|
|
520
|
-
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
521
|
-
const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
|
|
522
|
-
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
523
|
-
const findStateWithContent = {
|
|
524
|
-
[entriesStateKeyA]: findMultipleRelatedEntriesState,
|
|
525
|
-
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
502
|
+
default: {
|
|
503
|
+
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
504
|
+
const stateKeyA = `${a}KeysOf${capitalize(b)}`;
|
|
505
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
506
|
+
const findStateBase = {
|
|
507
|
+
[stateKeyA]: findMultipleRelatedKeysState,
|
|
508
|
+
[stateKeyB]: findMultipleRelatedKeysState
|
|
526
509
|
};
|
|
527
|
-
findState
|
|
528
|
-
|
|
529
|
-
|
|
510
|
+
let findState;
|
|
511
|
+
if (defaultContent) {
|
|
512
|
+
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
513
|
+
const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
|
|
514
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
515
|
+
const findStateWithContent = {
|
|
516
|
+
[entriesStateKeyA]: findMultipleRelatedEntriesState,
|
|
517
|
+
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
518
|
+
};
|
|
519
|
+
findState = Object.assign(findStateBase, findStateWithContent);
|
|
520
|
+
} else {
|
|
521
|
+
findState = findStateBase;
|
|
522
|
+
}
|
|
523
|
+
this.relations = relations;
|
|
524
|
+
this.findState = findState;
|
|
530
525
|
}
|
|
531
|
-
return {
|
|
532
|
-
relations,
|
|
533
|
-
findState
|
|
534
|
-
};
|
|
535
526
|
}
|
|
536
|
-
default:
|
|
537
|
-
throw new Error(`Invalid cardinality: ${options.cardinality}`);
|
|
538
527
|
}
|
|
528
|
+
transact(transactors, run) {
|
|
529
|
+
this.transactors = transactors;
|
|
530
|
+
run(this);
|
|
531
|
+
this.transactors = TRANSACTORS;
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
function join(options, defaultContent, store = internal.IMPLICIT.STORE) {
|
|
535
|
+
return new Join(options, defaultContent, store);
|
|
539
536
|
}
|
|
540
537
|
var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
541
538
|
function struct(options, store = internal.IMPLICIT.STORE) {
|
|
542
539
|
const atoms = Object.keys(options.default).reduce((acc, key) => {
|
|
543
540
|
const atomName = options.key + capitalize2(key) + `State`;
|
|
544
|
-
acc[atomName] = internal.
|
|
541
|
+
acc[atomName] = internal.createRegularAtom(
|
|
545
542
|
{
|
|
546
543
|
key: `${options.key}.${key}`,
|
|
547
544
|
default: options.default[key]
|
|
@@ -571,7 +568,7 @@ var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(
|
|
|
571
568
|
function structFamily(options) {
|
|
572
569
|
const atoms = Object.keys(options.default).reduce((acc, subKey) => {
|
|
573
570
|
const atomFamilyName = nameFamily(options.key, subKey);
|
|
574
|
-
acc[atomFamilyName] = internal.
|
|
571
|
+
acc[atomFamilyName] = internal.createRegularAtomFamily(
|
|
575
572
|
{
|
|
576
573
|
key: `${options.key}.${subKey}`,
|
|
577
574
|
default: options.default[subKey]
|
|
@@ -605,6 +602,7 @@ function until(loadable, fallback) {
|
|
|
605
602
|
return loadable;
|
|
606
603
|
}
|
|
607
604
|
|
|
605
|
+
exports.Join = Join;
|
|
608
606
|
exports.dict = dict;
|
|
609
607
|
exports.join = join;
|
|
610
608
|
exports.struct = struct;
|