Minor Changes
-
2d824e4: Add experimental machine invariants and transition postconditions. Declare named checks in
invariantsat the machine root and returnensuresfrom 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.inputmappers wheninvoke.srcis a registered actor logic value alongsideonDone: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 minimalcreateMachine+createActorbundle drops from29.88 kBto27.80 kBgzip with esbuild, and28.77 kBto26.83 kBgzip with terser) with no public API or behavior changes.