Skip to content

xstate@6.0.0-beta.9

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 05 Dec 07:30
· 7 commits to next since this release
4461bb6

Minor Changes

  • 2d824e4: Add experimental machine invariants and transition postconditions. Declare named checks in invariants at the machine root and return ensures from a transition function to check its before and after snapshots.

    const machine = createMachine({
      context: { balance: 10 },
      invariants: {
        nonNegativeBalance: ({ snapshot }) => snapshot.context.balance >= 0
      },
      on: {
        debit: ({ context }) => ({
          context: { balance: context.balance - 1 },
          ensures: {
            debitsOne: ({ before, after }) =>
              after.context.balance === before.context.balance - 1
          }
        })
      }
    });

Patch Changes

  • bfbbc60: Preserve contextual return typing for invoke.input mappers when invoke.src is a registered actor logic value alongside onDone:

    const validate = createAsyncLogic({
      run: async ({ input }: { input: { type: 'VALIDATE'; id: string } }) => ({
        ok: input.id.length > 0
      })
    });
    
    const s = setup({ actors: { validate } });
    
    s.createMachine({
      initial: 'a',
      states: {
        a: {
          invoke: {
            src: validate,
            input: () => ({ type: 'VALIDATE', id: 'x' }),
            onDone: ({ event }) => ({ target: 'b' })
          }
        },
        b: {}
      }
    });
  • f228a72: Reduced the minified and gzipped bundle size of xstate (a minimal createMachine + createActor bundle drops from 29.88 kB to 27.80 kB gzip with esbuild, and 28.77 kB to 26.83 kB gzip with terser) with no public API or behavior changes.