xstate@6.0.0-alpha.13
Pre-release
Pre-release
Minor Changes
-
bdc54dd: Added
createFSM(...)for flat, actor-compatible finite state machines.import { createActor, createFSM } from 'xstate'; const toggleLogic = createFSM({ initial: 'inactive', context: { count: 0 }, states: { inactive: { on: { toggle: { target: 'active', context: { count: 1 } } } }, active: { on: { toggle: ({ context }, enq) => { enq(() => console.log('toggled')); return { target: 'inactive', context: { count: context.count + 1 } }; } } } } }); const actor = createActor(toggleLogic).start(); actor.send({ type: 'toggle' });
createFSM(...)supports XState-style object transitions, function transitions,enqactions, initial input, stateinput, entry actions, and exit actions. Plain string targets are intentionally not supported; use object targets such as{ target: 'active' }.Simple FSM transitions preserve immutable public snapshots while using structural sharing and a lighter transition path for common
{ target },{ context }, and{ target, context }transitions.
Patch Changes
-
e297115: Object transition configs now support dynamic context patches with a
contextmapper.onDone: { target: 'done', context: ({ context, output }) => ({ answer: output, memory: [...context.memory, output] }) }