@@ -105,9 +105,10 @@ its extra control is required:
105105 ` AtomMachine.resume(machine, snapshot) ` for service-free machines.
106106- Use one invocation object: ` effect ` for one-shot work, ` after ` for a timer,
107107 ` logic ` for reusable process logic, and ` child ` for a complete child
108- statechart. ` Machine.invoke({...}) ` preserves owner context and source
109- channels across sibling lifecycle handlers. Use a direct object only when its
110- lifecycle handlers do not need source-derived context.
108+ statechart. ` Machine.invoke({...}) ` preserves owner state and source channels
109+ across sibling lifecycle handlers. Use ` definition.invoke({...}) ` when a
110+ callback uses ` self ` or ` parent ` ; the bound constructor preserves the
111+ definition's exact public input and ` parentEvents ` protocols.
111112- Use ` Machine.child(id, machine) ` for a complete statechart descriptor and
112113 ` Machine.childAddress<Event>(id) ` for a low-level process address. A logic
113114 invocation is addressable only when ` Machine.invoke ` receives that
@@ -517,8 +518,20 @@ targets an actor mailbox and is processed later. `enqueue.emit(...)` is neither:
517518it publishes a one-off outward notification. Observe it with
518519` ref.emissions ` , a hot non-replayed ` Stream ` that completes with the actor.
519520` ref.changes ` is stateful and begins with the current lifecycle snapshot.
520- Startup emissions occur before ` Machine.start ` returns and therefore are not
521- visible through the returned ref; use state for facts that must be retained.
521+ Use ` Machine.prepare(machine) ` to obtain ` changes ` and ` emissions ` before
522+ initialization. Subscribe to the desired stream and then evaluate
523+ ` prepared.start ` . ` Machine.start(machine) ` remains the one-step convenience
524+ when startup observation is unnecessary. Emissions are still never retained or
525+ replayed; state remains the representation for facts that must be retained.
526+
527+ ``` ts
528+ const prepared = yield * Machine .prepare (machine )
529+ yield * prepared .emissions .pipe (
530+ Stream .runForEach (handleEmission ),
531+ Effect .forkScoped ({ startImmediately: true })
532+ )
533+ const ref = yield * prepared .start
534+ ```
522535
523536For child-to-parent input, export a public builder protocol and reuse it at both
524537composition boundaries:
@@ -682,6 +695,33 @@ invoke: Machine.invoke({
682695})
683696` ` `
684697
698+ The standalone constructor cannot know the owning machine's input protocols,
699+ so its ` self ` and ` parent ` references are non-sendable. When a source sends
700+ through either reference, use the owning definition's bound constructor:
701+
702+ ` ` ` ts
703+ const definition = Machine .make ({
704+ events: Commands ,
705+ internalEvents: InternalEvents ,
706+ parentEvents: ParentEvents ,
707+ // ...
708+ })
709+
710+ const machine = definition .handle ({
711+ Saving: {
712+ invoke: definition .invoke ({
713+ id: " notify-parent" ,
714+ effect : ({ parent }) =>
715+ parent === undefined
716+ ? Effect .void
717+ : parent .send (ParentEvents .SaveStarted ()),
718+ onDone : ({ target }) => target .none (),
719+ onFailure : ({ target }) => target .none ()
720+ })
721+ }
722+ })
723+ ```
724+
685725A direct ` invoke: { ... } ` object remains available when lifecycle handlers do
686726not need source-derived context.
687727
@@ -729,9 +769,11 @@ parentRef.child(Editor)
729769parentAtom .child (Editor )
730770```
731771
732- Child emissions are delivered through the parent's internal protocol.
733- ` onSnapshot ` , ` onDone ` , and ` onFailure ` are direct parent transitions. Invoked
734- child IDs must be unique while simultaneously active.
772+ Child emissions remain on the child's hot ` emissions ` stream; they are never
773+ delivered implicitly to the parent. A child sends an input explicitly with
774+ ` enqueue.sendTo(parent, ParentEvents.Example()) ` . ` onSnapshot ` , ` onDone ` , and
775+ ` onFailure ` are direct parent transitions. Invoked child IDs must be unique
776+ while simultaneously active.
735777
736778Descriptors with the same id and machine identity address the same child, even
737779when independently constructed. The descriptor objects themselves are not
0 commit comments