@@ -435,9 +435,13 @@ type SnapshotValueByIdentifier<State, Path extends SnapshotIdentifier<State>> =
435435 Node extends { readonly path : Path ; readonly value : infer Value } ? Value : never
436436 : never
437437
438+ type SnapshotByIdentifier < State , Path extends SnapshotIdentifier < State > > = SnapshotNode < State > extends infer Node ?
439+ Node extends { readonly path : Path } ? Node : never
440+ : never
441+
438442type ChildState < Child extends Machine . ChildMachine . Any > = RefState < Machine . ChildMachine . Ref < Child > >
439443
440- const selectSnapshot = <
444+ const selectValueByPath = <
441445 State extends Machine . Machine . AtomicSnapshot < string , unknown > ,
442446 Path extends SnapshotIdentifier < State >
443447> (
@@ -448,6 +452,15 @@ const selectSnapshot = <
448452 Option . map ( ( snapshot ) => snapshot . value )
449453 ) as Option . Option < SnapshotValueByIdentifier < State , Path > >
450454
455+ const selectSnapshotByPath = <
456+ State extends Machine . Machine . AtomicSnapshot < string , unknown > ,
457+ Path extends SnapshotIdentifier < State >
458+ > (
459+ snapshot : State ,
460+ path : Path
461+ ) : Option . Option < SnapshotByIdentifier < State , Path > > =>
462+ Topology . getSnapshotByPath ( snapshot , path ) as Option . Option < SnapshotByIdentifier < State , Path > >
463+
451464export const select = <
452465 State extends Machine . Machine . AtomicSnapshot < string , unknown > ,
453466 Event ,
@@ -461,7 +474,24 @@ export const select = <
461474) : Atom . Atom <
462475 AsyncResult . AsyncResult < Option . Option < SnapshotValueByIdentifier < State , Path > > , StartError | Error >
463476> =>
464- Atom . mapResult ( self . result , ( snapshot ) => selectSnapshot ( snapshot , path ) ) . pipe (
477+ Atom . mapResult ( self . result , ( snapshot ) => selectValueByPath ( snapshot , path ) ) . pipe (
478+ Atom . withEquality ( Equal . equals )
479+ )
480+
481+ export const selectSnapshot = <
482+ State extends Machine . Machine . AtomicSnapshot < string , unknown > ,
483+ Event ,
484+ Error ,
485+ Output ,
486+ StartError ,
487+ const Path extends SnapshotIdentifier < State >
488+ > (
489+ self : MachineAtom < State , Event , Error , Output , StartError > ,
490+ path : Path
491+ ) : Atom . Atom <
492+ AsyncResult . AsyncResult < Option . Option < SnapshotByIdentifier < State , Path > > , StartError | Error >
493+ > =>
494+ Atom . mapResult ( self . result , ( snapshot ) => selectSnapshotByPath ( snapshot , path ) ) . pipe (
465495 Atom . withEquality ( Equal . equals )
466496 )
467497
@@ -480,7 +510,25 @@ export const selectChild = <
480510> =>
481511 Atom . mapResult (
482512 self . result ,
483- Option . flatMap ( ( snapshot ) => selectSnapshot ( snapshot , path ) )
513+ Option . flatMap ( ( snapshot ) => selectValueByPath ( snapshot , path ) )
514+ ) . pipe ( Atom . withEquality ( Equal . equals ) )
515+
516+ export const selectSnapshotChild = <
517+ Child extends Machine . ChildMachine . Any ,
518+ StartError ,
519+ const Path extends SnapshotIdentifier < ChildState < Child > >
520+ > (
521+ self : ChildMachineAtom < Child , StartError > ,
522+ path : Path
523+ ) : Atom . Atom <
524+ AsyncResult . AsyncResult <
525+ Option . Option < SnapshotByIdentifier < ChildState < Child > , Path > > ,
526+ StartError | RefError < Machine . ChildMachine . Ref < Child > >
527+ >
528+ > =>
529+ Atom . mapResult (
530+ self . result ,
531+ Option . flatMap ( ( snapshot ) => selectSnapshotByPath ( snapshot , path ) )
484532 ) . pipe ( Atom . withEquality ( Equal . equals ) )
485533
486534export const matches = <
0 commit comments