@@ -55,11 +55,11 @@ const Counter = Machine.make({
5555 id: " Counter" ,
5656 states: States .states ,
5757 events: [Event .cases .Start ],
58- initial : () => States .initial .Idle ( State . cases . Idle . make ({}) )
58+ initial : () => States .initial .Idle . from ({})
5959}).handle ({
6060 Idle: {
6161 on: {
62- Start : ({ target }) => target .full .Running ( State . cases . Running . make ({}) )
62+ Start : ({ target }) => target .full .Running . from ({})
6363 }
6464 },
6565 Running: {}
@@ -69,6 +69,23 @@ const Counter = Machine.make({
6969` initial ` is always a function. For a machine with an input schema, the
7070initializer receives the decoded input.
7171
72+ Builder methods accept an already constructed state value directly, or expose
73+ ` .from ` for constructing one safely from the state schema's make input:
74+
75+ ``` ts
76+ target .local .Running (decodedRunning )
77+ target .local .Running .from ({ startedAt: event .at })
78+ ```
79+
80+ Use the direct call when a decoded value already exists. Use ` .from ` when
81+ entering a state from fields. Construction runs through the schema's
82+ ` makeEffect ` while the machine plans the configuration, so constructor
83+ defaults and tagged-class identity are preserved and failed refinements become
84+ ` MachineSchemaDecodeError ` failures instead of synchronous throws. The same
85+ form is available on initial, local, branch, full, compound, parallel, and
86+ final builders. A ` .from ` builder result is therefore a machine construction
87+ instruction; it becomes a validated public snapshot when planning succeeds.
88+
7289Tagged classes are equally valid when cases need class methods or nominal
7390identity:
7491
@@ -157,8 +174,7 @@ Handlers implement behavior and output computation without repeating it:
157174const machine = Machine .make ({
158175 states: States .states ,
159176 events: [],
160- initial : () =>
161- States .initial .Form (State .cases .Form .make ({ draft: " " }), (form ) => form .Editing (State .cases .Editing .make ({})))
177+ initial : () => States .initial .Form .from ({ draft: " " }, (form ) => form .Editing .from ({}))
162178}).handle ({
163179 Form: {
164180 states: {
0 commit comments