@typeonce/effect-machine 0.27.0 → 0.28.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 +33 -4
- package/dist/internal/machine/atom.d.ts +9 -0
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +54 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +131 -6
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +64 -6
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/effect-atom-react.md +57 -79
- package/docs/machine-review.md +32 -27
- package/package.json +1 -1
- package/src/internal/machine/atom.ts +111 -1
- package/src/unstable/reactivity/AtomMachine.ts +466 -59
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @since 0.4.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { dual } from "effect/Function"
|
|
7
8
|
import type * as Option from "effect/Option"
|
|
8
9
|
import type * as Schema from "effect/Schema"
|
|
9
10
|
import type * as Scope from "effect/Scope"
|
|
@@ -351,6 +352,37 @@ type SnapshotByIdentifier<State, Path extends SnapshotIdentifier<State>> = Snaps
|
|
|
351
352
|
|
|
352
353
|
type ChildState<Child extends Machine.ChildMachine.Any> = RefState<Machine.ChildMachine.Ref<Child>>
|
|
353
354
|
|
|
355
|
+
type ChildSnapshot<Child extends Machine.ChildMachine.Any> = Machine.Machine.Snapshot<
|
|
356
|
+
Machine.Machine.States<Child["machine"]>
|
|
357
|
+
>
|
|
358
|
+
|
|
359
|
+
const InvalidSelectorPathTypeId = "~effect/reactivity/AtomMachine/InvalidSelectorPath"
|
|
360
|
+
const SelectorProjectionTypeId = "~effect/reactivity/AtomMachine/SelectorProjection"
|
|
361
|
+
|
|
362
|
+
type SelectorProjectionKind =
|
|
363
|
+
| "select"
|
|
364
|
+
| "selectSnapshot"
|
|
365
|
+
| "matches"
|
|
366
|
+
| "selectChild"
|
|
367
|
+
| "selectSnapshotChild"
|
|
368
|
+
| "matchesChild"
|
|
369
|
+
|
|
370
|
+
interface SelectorProjection<Kind extends SelectorProjectionKind, Path extends string> {
|
|
371
|
+
readonly [SelectorProjectionTypeId]: {
|
|
372
|
+
readonly kind: Kind
|
|
373
|
+
readonly path: Path
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
type EnsureSelectorPath<State, Path extends string> = [Path] extends [SnapshotIdentifier<State>] ? unknown : {
|
|
378
|
+
readonly [InvalidSelectorPathTypeId]: Path
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
type EnsureValuedSelectorPath<State, Path extends string> = [Path] extends [ValuedSnapshotIdentifier<State>] ? unknown
|
|
382
|
+
: {
|
|
383
|
+
readonly [InvalidSelectorPathTypeId]: Path
|
|
384
|
+
}
|
|
385
|
+
|
|
354
386
|
/**
|
|
355
387
|
* Selects the typed value for an active state path.
|
|
356
388
|
*
|
|
@@ -385,17 +417,49 @@ type ChildState<Child extends Machine.ChildMachine.Any> = RefState<Machine.Child
|
|
|
385
417
|
* @category combinators
|
|
386
418
|
* @since 0.4.0
|
|
387
419
|
*/
|
|
388
|
-
export const select:
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
420
|
+
export const select: {
|
|
421
|
+
<
|
|
422
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown> = never,
|
|
423
|
+
Event = never,
|
|
424
|
+
Error = never,
|
|
425
|
+
Output = never,
|
|
426
|
+
StartError = never,
|
|
427
|
+
Emitted = never,
|
|
428
|
+
const Path extends ValuedSnapshotIdentifier<State> = ValuedSnapshotIdentifier<State>
|
|
429
|
+
>(path: Path):
|
|
430
|
+
& SelectorProjection<"select", Path>
|
|
431
|
+
& ((self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Atom.Atom<
|
|
432
|
+
AsyncResult.AsyncResult<Option.Option<SnapshotValueByIdentifier<State, Path>>, StartError | Error>
|
|
433
|
+
>)
|
|
434
|
+
<const Path extends string>(path: Path):
|
|
435
|
+
& SelectorProjection<"select", Path>
|
|
436
|
+
& (<
|
|
437
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown>,
|
|
438
|
+
Event,
|
|
439
|
+
Error,
|
|
440
|
+
Output,
|
|
441
|
+
StartError,
|
|
442
|
+
Emitted
|
|
443
|
+
>(
|
|
444
|
+
self: MachineAtom<State, Event, Error, Output, StartError, Emitted> & EnsureValuedSelectorPath<State, Path>
|
|
445
|
+
) => Atom.Atom<
|
|
446
|
+
AsyncResult.AsyncResult<
|
|
447
|
+
Option.Option<SnapshotValueByIdentifier<State, Extract<Path, ValuedSnapshotIdentifier<State>>>>,
|
|
448
|
+
StartError | Error
|
|
449
|
+
>
|
|
450
|
+
>)
|
|
451
|
+
<
|
|
452
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown>,
|
|
453
|
+
Event,
|
|
454
|
+
Error,
|
|
455
|
+
Output,
|
|
456
|
+
StartError,
|
|
457
|
+
Emitted,
|
|
458
|
+
const Path extends ValuedSnapshotIdentifier<State>
|
|
459
|
+
>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>, path: Path): Atom.Atom<
|
|
460
|
+
AsyncResult.AsyncResult<Option.Option<SnapshotValueByIdentifier<State, Path>>, StartError | Error>
|
|
461
|
+
>
|
|
462
|
+
} = dual(2, internal.select)
|
|
399
463
|
|
|
400
464
|
/**
|
|
401
465
|
* Selects the typed logical snapshot for an active state path.
|
|
@@ -407,17 +471,49 @@ export const select: <
|
|
|
407
471
|
* @category combinators
|
|
408
472
|
* @since 0.7.0
|
|
409
473
|
*/
|
|
410
|
-
export const selectSnapshot:
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
474
|
+
export const selectSnapshot: {
|
|
475
|
+
<
|
|
476
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown> = never,
|
|
477
|
+
Event = never,
|
|
478
|
+
Error = never,
|
|
479
|
+
Output = never,
|
|
480
|
+
StartError = never,
|
|
481
|
+
Emitted = never,
|
|
482
|
+
const Path extends SnapshotIdentifier<State> = SnapshotIdentifier<State>
|
|
483
|
+
>(path: Path):
|
|
484
|
+
& SelectorProjection<"selectSnapshot", Path>
|
|
485
|
+
& ((self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Atom.Atom<
|
|
486
|
+
AsyncResult.AsyncResult<Option.Option<SnapshotByIdentifier<State, Path>>, StartError | Error>
|
|
487
|
+
>)
|
|
488
|
+
<const Path extends string>(path: Path):
|
|
489
|
+
& SelectorProjection<"selectSnapshot", Path>
|
|
490
|
+
& (<
|
|
491
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown>,
|
|
492
|
+
Event,
|
|
493
|
+
Error,
|
|
494
|
+
Output,
|
|
495
|
+
StartError,
|
|
496
|
+
Emitted
|
|
497
|
+
>(
|
|
498
|
+
self: MachineAtom<State, Event, Error, Output, StartError, Emitted> & EnsureSelectorPath<State, Path>
|
|
499
|
+
) => Atom.Atom<
|
|
500
|
+
AsyncResult.AsyncResult<
|
|
501
|
+
Option.Option<SnapshotByIdentifier<State, Extract<Path, SnapshotIdentifier<State>>>>,
|
|
502
|
+
StartError | Error
|
|
503
|
+
>
|
|
504
|
+
>)
|
|
505
|
+
<
|
|
506
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown>,
|
|
507
|
+
Event,
|
|
508
|
+
Error,
|
|
509
|
+
Output,
|
|
510
|
+
StartError,
|
|
511
|
+
Emitted,
|
|
512
|
+
const Path extends SnapshotIdentifier<State>
|
|
513
|
+
>(self: MachineAtom<State, Event, Error, Output, StartError, Emitted>, path: Path): Atom.Atom<
|
|
514
|
+
AsyncResult.AsyncResult<Option.Option<SnapshotByIdentifier<State, Path>>, StartError | Error>
|
|
515
|
+
>
|
|
516
|
+
} = dual(2, internal.selectSnapshot)
|
|
421
517
|
|
|
422
518
|
/**
|
|
423
519
|
* Selects the typed value for an active state path in a directly owned child.
|
|
@@ -436,16 +532,45 @@ export const selectSnapshot: <
|
|
|
436
532
|
* @category combinators
|
|
437
533
|
* @since 0.4.0
|
|
438
534
|
*/
|
|
439
|
-
export const selectChild:
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
StartError
|
|
535
|
+
export const selectChild: {
|
|
536
|
+
<
|
|
537
|
+
Child extends Machine.ChildMachine.Any = never,
|
|
538
|
+
StartError = never,
|
|
539
|
+
const Path extends ValuedSnapshotIdentifier<ChildState<Child>> = ValuedSnapshotIdentifier<ChildState<Child>>
|
|
540
|
+
>(path: Path):
|
|
541
|
+
& SelectorProjection<"selectChild", Path>
|
|
542
|
+
& ((self: ChildMachineAtom<Child, StartError>) => Atom.Atom<
|
|
543
|
+
AsyncResult.AsyncResult<
|
|
544
|
+
Option.Option<SnapshotValueByIdentifier<ChildState<Child>, Path>>,
|
|
545
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
546
|
+
>
|
|
547
|
+
>)
|
|
548
|
+
<const Path extends string>(path: Path):
|
|
549
|
+
& SelectorProjection<"selectChild", Path>
|
|
550
|
+
& (<
|
|
551
|
+
Child extends Machine.ChildMachine.Any,
|
|
552
|
+
StartError
|
|
553
|
+
>(
|
|
554
|
+
self: ChildMachineAtom<Child, StartError> & EnsureValuedSelectorPath<ChildState<Child>, Path>
|
|
555
|
+
) => Atom.Atom<
|
|
556
|
+
AsyncResult.AsyncResult<
|
|
557
|
+
Option.Option<
|
|
558
|
+
SnapshotValueByIdentifier<ChildState<Child>, Extract<Path, ValuedSnapshotIdentifier<ChildState<Child>>>>
|
|
559
|
+
>,
|
|
560
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
561
|
+
>
|
|
562
|
+
>)
|
|
563
|
+
<
|
|
564
|
+
Child extends Machine.ChildMachine.Any,
|
|
565
|
+
StartError,
|
|
566
|
+
const Path extends ValuedSnapshotIdentifier<ChildState<Child>>
|
|
567
|
+
>(self: ChildMachineAtom<Child, StartError>, path: Path): Atom.Atom<
|
|
568
|
+
AsyncResult.AsyncResult<
|
|
569
|
+
Option.Option<SnapshotValueByIdentifier<ChildState<Child>, Path>>,
|
|
570
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
571
|
+
>
|
|
447
572
|
>
|
|
448
|
-
|
|
573
|
+
} = dual(2, internal.selectChild)
|
|
449
574
|
|
|
450
575
|
/**
|
|
451
576
|
* Selects the typed logical snapshot for an active state path in an invoked
|
|
@@ -458,16 +583,43 @@ export const selectChild: <
|
|
|
458
583
|
* @category combinators
|
|
459
584
|
* @since 0.7.0
|
|
460
585
|
*/
|
|
461
|
-
export const selectSnapshotChild:
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
StartError
|
|
586
|
+
export const selectSnapshotChild: {
|
|
587
|
+
<
|
|
588
|
+
Child extends Machine.ChildMachine.Any = never,
|
|
589
|
+
StartError = never,
|
|
590
|
+
const Path extends SnapshotIdentifier<ChildState<Child>> = SnapshotIdentifier<ChildState<Child>>
|
|
591
|
+
>(path: Path):
|
|
592
|
+
& SelectorProjection<"selectSnapshotChild", Path>
|
|
593
|
+
& ((self: ChildMachineAtom<Child, StartError>) => Atom.Atom<
|
|
594
|
+
AsyncResult.AsyncResult<
|
|
595
|
+
Option.Option<SnapshotByIdentifier<ChildState<Child>, Path>>,
|
|
596
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
597
|
+
>
|
|
598
|
+
>)
|
|
599
|
+
<const Path extends string>(path: Path):
|
|
600
|
+
& SelectorProjection<"selectSnapshotChild", Path>
|
|
601
|
+
& (<
|
|
602
|
+
Child extends Machine.ChildMachine.Any,
|
|
603
|
+
StartError
|
|
604
|
+
>(
|
|
605
|
+
self: ChildMachineAtom<Child, StartError> & EnsureSelectorPath<ChildState<Child>, Path>
|
|
606
|
+
) => Atom.Atom<
|
|
607
|
+
AsyncResult.AsyncResult<
|
|
608
|
+
Option.Option<SnapshotByIdentifier<ChildState<Child>, Extract<Path, SnapshotIdentifier<ChildState<Child>>>>>,
|
|
609
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
610
|
+
>
|
|
611
|
+
>)
|
|
612
|
+
<
|
|
613
|
+
Child extends Machine.ChildMachine.Any,
|
|
614
|
+
StartError,
|
|
615
|
+
const Path extends SnapshotIdentifier<ChildState<Child>>
|
|
616
|
+
>(self: ChildMachineAtom<Child, StartError>, path: Path): Atom.Atom<
|
|
617
|
+
AsyncResult.AsyncResult<
|
|
618
|
+
Option.Option<SnapshotByIdentifier<ChildState<Child>, Path>>,
|
|
619
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
620
|
+
>
|
|
469
621
|
>
|
|
470
|
-
|
|
622
|
+
} = dual(2, internal.selectSnapshotChild)
|
|
471
623
|
|
|
472
624
|
/**
|
|
473
625
|
* Returns whether a state path is active.
|
|
@@ -501,18 +653,45 @@ export const selectSnapshotChild: <
|
|
|
501
653
|
* @category combinators
|
|
502
654
|
* @since 0.4.0
|
|
503
655
|
*/
|
|
504
|
-
export const matches:
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
>
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
656
|
+
export const matches: {
|
|
657
|
+
<
|
|
658
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown> = never,
|
|
659
|
+
Event = never,
|
|
660
|
+
Error = never,
|
|
661
|
+
Output = never,
|
|
662
|
+
StartError = never,
|
|
663
|
+
Emitted = never,
|
|
664
|
+
const Path extends SnapshotIdentifier<State> = SnapshotIdentifier<State>
|
|
665
|
+
>(path: Path):
|
|
666
|
+
& SelectorProjection<"matches", Path>
|
|
667
|
+
& ((self: MachineAtom<State, Event, Error, Output, StartError, Emitted>) => Atom.Atom<
|
|
668
|
+
AsyncResult.AsyncResult<boolean, StartError | Error>
|
|
669
|
+
>)
|
|
670
|
+
<const Path extends string>(path: Path):
|
|
671
|
+
& SelectorProjection<"matches", Path>
|
|
672
|
+
& (<
|
|
673
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown>,
|
|
674
|
+
Event,
|
|
675
|
+
Error,
|
|
676
|
+
Output,
|
|
677
|
+
StartError,
|
|
678
|
+
Emitted
|
|
679
|
+
>(
|
|
680
|
+
self: MachineAtom<State, Event, Error, Output, StartError, Emitted> & EnsureSelectorPath<State, Path>
|
|
681
|
+
) => Atom.Atom<AsyncResult.AsyncResult<boolean, StartError | Error>>)
|
|
682
|
+
<
|
|
683
|
+
State extends Machine.Machine.AtomicSnapshot<string, unknown>,
|
|
684
|
+
Event,
|
|
685
|
+
Error,
|
|
686
|
+
Output,
|
|
687
|
+
StartError,
|
|
688
|
+
Emitted,
|
|
689
|
+
const Path extends SnapshotIdentifier<State>
|
|
690
|
+
>(
|
|
691
|
+
self: MachineAtom<State, Event, Error, Output, StartError, Emitted>,
|
|
692
|
+
path: Path
|
|
693
|
+
): Atom.Atom<AsyncResult.AsyncResult<boolean, StartError | Error>>
|
|
694
|
+
} = dual(2, internal.matches)
|
|
516
695
|
|
|
517
696
|
/**
|
|
518
697
|
* Returns whether a state path is active in a directly owned child.
|
|
@@ -524,13 +703,34 @@ export const matches: <
|
|
|
524
703
|
* @category combinators
|
|
525
704
|
* @since 0.4.0
|
|
526
705
|
*/
|
|
527
|
-
export const matchesChild:
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
706
|
+
export const matchesChild: {
|
|
707
|
+
<
|
|
708
|
+
Child extends Machine.ChildMachine.Any = never,
|
|
709
|
+
StartError = never,
|
|
710
|
+
const Path extends SnapshotIdentifier<ChildState<Child>> = SnapshotIdentifier<ChildState<Child>>
|
|
711
|
+
>(path: Path):
|
|
712
|
+
& SelectorProjection<"matchesChild", Path>
|
|
713
|
+
& ((self: ChildMachineAtom<Child, StartError>) => Atom.Atom<
|
|
714
|
+
AsyncResult.AsyncResult<boolean, StartError | RefError<Machine.ChildMachine.Ref<Child>>>
|
|
715
|
+
>)
|
|
716
|
+
<const Path extends string>(path: Path):
|
|
717
|
+
& SelectorProjection<"matchesChild", Path>
|
|
718
|
+
& (<
|
|
719
|
+
Child extends Machine.ChildMachine.Any,
|
|
720
|
+
StartError
|
|
721
|
+
>(
|
|
722
|
+
self: ChildMachineAtom<Child, StartError> & EnsureSelectorPath<ChildState<Child>, Path>
|
|
723
|
+
) => Atom.Atom<
|
|
724
|
+
AsyncResult.AsyncResult<boolean, StartError | RefError<Machine.ChildMachine.Ref<Child>>>
|
|
725
|
+
>)
|
|
726
|
+
<
|
|
727
|
+
Child extends Machine.ChildMachine.Any,
|
|
728
|
+
StartError,
|
|
729
|
+
const Path extends SnapshotIdentifier<ChildState<Child>>
|
|
730
|
+
>(self: ChildMachineAtom<Child, StartError>, path: Path): Atom.Atom<
|
|
731
|
+
AsyncResult.AsyncResult<boolean, StartError | RefError<Machine.ChildMachine.Ref<Child>>>
|
|
732
|
+
>
|
|
733
|
+
} = dual(2, internal.matchesChild)
|
|
534
734
|
|
|
535
735
|
const BoundRequirementsTypeId = "~effect/reactivity/AtomMachine/BoundRequirements"
|
|
536
736
|
|
|
@@ -602,6 +802,98 @@ type MachineAtomOf<M extends Machine.Machine.Any, RuntimeError> = MachineAtom<
|
|
|
602
802
|
Machine.Machine.EmittedEvent<M>
|
|
603
803
|
>
|
|
604
804
|
|
|
805
|
+
type FamilyBridge = MachineAtom<any, never, any, any, any, any> | ChildMachineAtom<any, any>
|
|
806
|
+
|
|
807
|
+
type RootFamilySelectorProjection<State> =
|
|
808
|
+
| SelectorProjection<"select", ValuedSnapshotIdentifier<State>>
|
|
809
|
+
| SelectorProjection<"selectSnapshot", SnapshotIdentifier<State>>
|
|
810
|
+
| SelectorProjection<"matches", SnapshotIdentifier<State>>
|
|
811
|
+
|
|
812
|
+
type ChildFamilySelectorProjection<Child extends Machine.ChildMachine.Any> =
|
|
813
|
+
| SelectorProjection<"selectChild", ValuedSnapshotIdentifier<ChildSnapshot<Child>>>
|
|
814
|
+
| SelectorProjection<"selectSnapshotChild", SnapshotIdentifier<ChildSnapshot<Child>>>
|
|
815
|
+
| SelectorProjection<"matchesChild", SnapshotIdentifier<ChildSnapshot<Child>>>
|
|
816
|
+
|
|
817
|
+
type FamilyProjectionRecord<Bridge extends FamilyBridge, SelectorProjection = never> = Readonly<
|
|
818
|
+
Record<string, ((bridge: Bridge) => Atom.Atom<any>) | SelectorProjection>
|
|
819
|
+
>
|
|
820
|
+
|
|
821
|
+
type FamilyProjectedSelectorAtom<
|
|
822
|
+
Kind extends SelectorProjectionKind,
|
|
823
|
+
Path extends string,
|
|
824
|
+
Bridge extends FamilyBridge
|
|
825
|
+
> = Bridge extends
|
|
826
|
+
MachineAtom<infer State, infer _Event, infer Error, infer _Output, infer StartError, infer _Emitted> ?
|
|
827
|
+
Kind extends "select" ? Atom.Atom<
|
|
828
|
+
AsyncResult.AsyncResult<
|
|
829
|
+
Option.Option<SnapshotValueByIdentifier<State, Extract<Path, ValuedSnapshotIdentifier<State>>>>,
|
|
830
|
+
StartError | Error
|
|
831
|
+
>
|
|
832
|
+
>
|
|
833
|
+
: Kind extends "selectSnapshot" ? Atom.Atom<
|
|
834
|
+
AsyncResult.AsyncResult<
|
|
835
|
+
Option.Option<SnapshotByIdentifier<State, Extract<Path, SnapshotIdentifier<State>>>>,
|
|
836
|
+
StartError | Error
|
|
837
|
+
>
|
|
838
|
+
>
|
|
839
|
+
: Kind extends "matches" ? Atom.Atom<AsyncResult.AsyncResult<boolean, StartError | Error>>
|
|
840
|
+
: never
|
|
841
|
+
: Bridge extends ChildMachineAtom<infer Child, infer StartError> ? Kind extends "selectChild" ? Atom.Atom<
|
|
842
|
+
AsyncResult.AsyncResult<
|
|
843
|
+
Option.Option<
|
|
844
|
+
SnapshotValueByIdentifier<
|
|
845
|
+
ChildSnapshot<Child>,
|
|
846
|
+
Extract<Path, ValuedSnapshotIdentifier<ChildSnapshot<Child>>>
|
|
847
|
+
>
|
|
848
|
+
>,
|
|
849
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
850
|
+
>
|
|
851
|
+
>
|
|
852
|
+
: Kind extends "selectSnapshotChild" ? Atom.Atom<
|
|
853
|
+
AsyncResult.AsyncResult<
|
|
854
|
+
Option.Option<
|
|
855
|
+
SnapshotByIdentifier<ChildSnapshot<Child>, Extract<Path, SnapshotIdentifier<ChildSnapshot<Child>>>>
|
|
856
|
+
>,
|
|
857
|
+
StartError | RefError<Machine.ChildMachine.Ref<Child>>
|
|
858
|
+
>
|
|
859
|
+
>
|
|
860
|
+
: Kind extends "matchesChild" ? Atom.Atom<
|
|
861
|
+
AsyncResult.AsyncResult<boolean, StartError | RefError<Machine.ChildMachine.Ref<Child>>>
|
|
862
|
+
>
|
|
863
|
+
: never
|
|
864
|
+
: never
|
|
865
|
+
|
|
866
|
+
type FamilyProjectedAtom<Projection, Bridge extends FamilyBridge> = Projection extends
|
|
867
|
+
SelectorProjection<infer Kind, infer Path> ? FamilyProjectedSelectorAtom<Kind, Path, Bridge>
|
|
868
|
+
: Projection extends (bridge: Bridge) => infer Source ? Source extends Atom.Atom<any> ? Source : never
|
|
869
|
+
: never
|
|
870
|
+
|
|
871
|
+
type FamilyAtoms<
|
|
872
|
+
Key,
|
|
873
|
+
Bridge extends FamilyBridge,
|
|
874
|
+
Projections extends Readonly<Record<string, unknown>>
|
|
875
|
+
> = {
|
|
876
|
+
readonly [Name in keyof Projections]: (
|
|
877
|
+
key: Key
|
|
878
|
+
) => Atom.WithoutSerializable<FamilyProjectedAtom<Projections[Name], Bridge>>
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
const FamilyInputRequiredTypeId = "~effect/reactivity/AtomMachine/FamilyInputRequired"
|
|
882
|
+
|
|
883
|
+
type EnsureFamilyInput<M extends Machine.Machine.Any> = [Machine.Machine.Input<M>] extends [never] ? {
|
|
884
|
+
readonly [FamilyInputRequiredTypeId]: "AtomMachine.family requires a machine with startup input"
|
|
885
|
+
}
|
|
886
|
+
: unknown
|
|
887
|
+
|
|
888
|
+
type FamilyOptions<
|
|
889
|
+
Key,
|
|
890
|
+
Bridge extends FamilyBridge,
|
|
891
|
+
Projections extends Readonly<Record<string, unknown>>
|
|
892
|
+
> = {
|
|
893
|
+
readonly atoms: Projections
|
|
894
|
+
readonly label?: (key: Key, atomName: keyof Projections & string) => string | undefined
|
|
895
|
+
}
|
|
896
|
+
|
|
605
897
|
type ResumedMachineAtomOf<M extends Machine.Machine.Any, RuntimeError> = MachineAtom<
|
|
606
898
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
607
899
|
Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>,
|
|
@@ -644,8 +936,123 @@ export interface Bound<Services, RuntimeError = never> {
|
|
|
644
936
|
& Machine.Machine.RootCompatible<Machine.Machine.ParentEvents<NoInfer<M>>>,
|
|
645
937
|
snapshot: Machine.Machine.Snapshot<Machine.Machine.States<M>>
|
|
646
938
|
) => ResumedMachineAtomOf<M, RuntimeError>
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Creates retained atom families for independent machine inputs using the
|
|
942
|
+
* bound runtime.
|
|
943
|
+
*
|
|
944
|
+
* Each machine input is also the family key. Every projected atom retains
|
|
945
|
+
* its private machine bridge while the projected atom remains reachable.
|
|
946
|
+
*
|
|
947
|
+
* @since 0.28.0
|
|
948
|
+
*/
|
|
949
|
+
readonly family: <
|
|
950
|
+
M extends Machine.Machine.Any,
|
|
951
|
+
const Projections extends FamilyProjectionRecord<
|
|
952
|
+
MachineAtomOf<NoInfer<M>, RuntimeError>,
|
|
953
|
+
RootFamilySelectorProjection<Machine.Machine.Snapshot<Machine.Machine.States<NoInfer<M>>>>
|
|
954
|
+
>
|
|
955
|
+
>(
|
|
956
|
+
machine:
|
|
957
|
+
& M
|
|
958
|
+
& EnsureBoundRequirements<Services, NoInfer<M>>
|
|
959
|
+
& EnsureMachineExecutable<NoInfer<M>>
|
|
960
|
+
& Machine.Machine.RootCompatible<Machine.Machine.ParentEvents<NoInfer<M>>>
|
|
961
|
+
& EnsureFamilyInput<NoInfer<M>>,
|
|
962
|
+
options: FamilyOptions<
|
|
963
|
+
Machine.Machine.Input<NoInfer<M>>,
|
|
964
|
+
MachineAtomOf<NoInfer<M>, RuntimeError>,
|
|
965
|
+
Projections
|
|
966
|
+
>
|
|
967
|
+
) => FamilyAtoms<Machine.Machine.Input<M>, MachineAtomOf<M, RuntimeError>, Projections>
|
|
647
968
|
}
|
|
648
969
|
|
|
970
|
+
/**
|
|
971
|
+
* Creates retained atom families for independent machine inputs.
|
|
972
|
+
*
|
|
973
|
+
* The machine input is both startup input and family identity. Each property
|
|
974
|
+
* in `atoms` projects one public atom family from a private machine bridge.
|
|
975
|
+
* Retaining any projected atom retains that bridge without keeping its
|
|
976
|
+
* registry runtime mounted. Keys follow Effect `Equal` and `Hash` semantics.
|
|
977
|
+
* The optional `label` function labels each public projected atom.
|
|
978
|
+
*
|
|
979
|
+
* **Example**
|
|
980
|
+
*
|
|
981
|
+
* ```ts
|
|
982
|
+
* const processAtoms = AtomMachine.family(processMachine, {
|
|
983
|
+
* atoms: {
|
|
984
|
+
* ready: AtomMachine.matches("Ready"),
|
|
985
|
+
* state: (machine) => machine.state,
|
|
986
|
+
* send: (machine) => machine.send
|
|
987
|
+
* }
|
|
988
|
+
* })
|
|
989
|
+
*
|
|
990
|
+
* const readyAtom = processAtoms.ready("effect")
|
|
991
|
+
* const sendAtom = processAtoms.send("effect")
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* @category constructors
|
|
995
|
+
* @since 0.28.0
|
|
996
|
+
*/
|
|
997
|
+
export const family: <
|
|
998
|
+
M extends Machine.Machine.Any,
|
|
999
|
+
const Projections extends FamilyProjectionRecord<
|
|
1000
|
+
MachineAtomOf<NoInfer<M>, never>,
|
|
1001
|
+
RootFamilySelectorProjection<Machine.Machine.Snapshot<Machine.Machine.States<NoInfer<M>>>>
|
|
1002
|
+
>
|
|
1003
|
+
>(
|
|
1004
|
+
machine:
|
|
1005
|
+
& M
|
|
1006
|
+
& EnsureNoExternalRequirements<MachineRequirementsOf<NoInfer<M>>>
|
|
1007
|
+
& EnsureMachineExecutable<NoInfer<M>>
|
|
1008
|
+
& Machine.Machine.RootCompatible<Machine.Machine.ParentEvents<NoInfer<M>>>
|
|
1009
|
+
& EnsureFamilyInput<NoInfer<M>>,
|
|
1010
|
+
options: FamilyOptions<
|
|
1011
|
+
Machine.Machine.Input<NoInfer<M>>,
|
|
1012
|
+
MachineAtomOf<NoInfer<M>, never>,
|
|
1013
|
+
Projections
|
|
1014
|
+
>
|
|
1015
|
+
) => FamilyAtoms<Machine.Machine.Input<M>, MachineAtomOf<M, never>, Projections> = internal.family as any
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Creates retained atom families for keyed direct-child lookup.
|
|
1019
|
+
*
|
|
1020
|
+
* The `child` function maps each family key to one direct child descriptor.
|
|
1021
|
+
* Every projected atom retains the resulting child bridge while the projected
|
|
1022
|
+
* atom remains reachable. Keys follow Effect `Equal` and `Hash` semantics.
|
|
1023
|
+
*
|
|
1024
|
+
* **Example**
|
|
1025
|
+
*
|
|
1026
|
+
* ```ts
|
|
1027
|
+
* const Plant = Machine.childFamily(plantMachine)
|
|
1028
|
+
*
|
|
1029
|
+
* const plantAtoms = AtomMachine.familyChild(parentMachineAtom, {
|
|
1030
|
+
* child: (plantId: string) => Plant(plantId),
|
|
1031
|
+
* atoms: {
|
|
1032
|
+
* broken: AtomMachine.matchesChild("Broken"),
|
|
1033
|
+
* state: (child) => child.state,
|
|
1034
|
+
* send: (child) => child.send
|
|
1035
|
+
* }
|
|
1036
|
+
* })
|
|
1037
|
+
* ```
|
|
1038
|
+
*
|
|
1039
|
+
* @category constructors
|
|
1040
|
+
* @since 0.28.0
|
|
1041
|
+
*/
|
|
1042
|
+
export const familyChild: <
|
|
1043
|
+
Key,
|
|
1044
|
+
Parent extends MachineAtom<any, never, any, any, any, any> | ChildMachineAtom<any, any>,
|
|
1045
|
+
Child extends Machine.ChildMachine.Any,
|
|
1046
|
+
const Projections extends FamilyProjectionRecord<ChildOf<Parent, Child>, ChildFamilySelectorProjection<Child>>
|
|
1047
|
+
>(
|
|
1048
|
+
parent: Parent,
|
|
1049
|
+
options: {
|
|
1050
|
+
readonly child: (key: Key) => Child
|
|
1051
|
+
readonly atoms: Projections
|
|
1052
|
+
readonly label?: (key: Key, atomName: keyof Projections & string) => string | undefined
|
|
1053
|
+
}
|
|
1054
|
+
) => FamilyAtoms<Key, ChildOf<Parent, Child>, Projections> = internal.familyChild as any
|
|
1055
|
+
|
|
649
1056
|
/**
|
|
650
1057
|
* Creates atoms backed by a running machine.
|
|
651
1058
|
*
|