Skip to content

xstate@5.0.0-beta.31

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 27 Sep 11:44
· 333 commits to main since this release
9e45969

Major Changes

  • #4306 30e3cb216 Thanks @Andarist! - The final output of a state machine is now specified directly in the output property of the machine config:

    const machine = createMachine({
      initial: 'started',
      states: {
        started: {
          // ...
        },
        finished: {
          type: 'final'
          // moved to the top level
          //
          // output: {
          //   status: 200
          // }
        }
      },
      // This will be the final output of the machine
      // present on `snapshot.output` and in the done events received by the parent
      // when the machine reaches the top-level final state ("finished")
      output: {
        status: 200
      }
    });

Minor Changes

  • #4172 aeef5e2d0 Thanks @davidkpiano! - The onSnapshot: { ... } transition object is now supported for invoked machines, observables, promises, and transition functions:

    const machine = createMachine({
      // ...
      invoke: [
        {
          src: createMachine({ ... }),
          onSnapshot: {
            actions: (context, event) => {
              event.snapshot; // machine state
            }
          }
        },
        {
          src: fromObservable(() => ...),
          onSnapshot: {
            actions: (context, event) => {
              event.snapshot; // observable value
            }
          }
        },
        {
          src: fromTransition((state, event) => { ... }, /* ... */),
          onSnapshot: {
            actions: (context, event) => {
              event.snapshot; // transition function return value
            }
          }
        }
      ]
    });

Patch Changes

  • #4307 0c7b3aa3d Thanks @davidkpiano! - The input of a callback actor created with fromCallback(...) will now be properly restored when the actor is persisted.