xstate

Actor-based state management & orchestration for complex app logic.

MIT License

Downloads
14.3M
Stars
26.2K
Committers
362

Bot releases are visible (Hide)

xstate - [email protected]

Published by github-actions[bot] 8 months ago

Patch Changes

  • #4739 15b7dd1f0 Thanks @devanfarrell! - Removed this from machine snapshot methods to fix issues with accessing those methods from union of actors and their snapshots.
xstate - [email protected]

Published by github-actions[bot] 8 months ago

Minor Changes

  • #4290 7a8796f80 Thanks @davidkpiano! - An error will now be thrown if an incompatible state value is passed to machine.resolveState({ value }).

  • #4693 11b6a1ae1 Thanks @davidkpiano! - You can now inspect microsteps (@xstate.microstep) and actions (@xstate.action):

    const machine = createMachine({
      initial: 'a',
      states: {
        a: {
          on: {
            event: 'b'
          }
        },
        b: {
          entry: 'someAction',
          always: 'c'
        },
        c: {}
      }
    });
    
    const actor = createActor(machine, {
      inspect: (inspEvent) => {
        if (inspEvent.type === '@xstate.microstep') {
          console.log(inspEvent.snapshot);
          // logs:
          // { value: 'a', … }
          // { value: 'b', … }
          // { value: 'c', … }
    
          console.log(inspEvent.event);
          // logs:
          // { type: 'event', … }
        } else if (inspEvent.type === '@xstate.action') {
          console.log(inspEvent.action);
          // logs:
          // { type: 'someAction', … }
        }
      }
    });
    
    actor.start();
    
    actor.send({ type: 'event' });
    
xstate - @xstate/[email protected]

Published by github-actions[bot] 8 months ago

Minor Changes

  • #4231 c2402e7bc Thanks @davidkpiano! - The actor passed to useSelector(actor, selector) is now allowed to be undefined for an actor that may not exist yet. For actors that may be undefined, the snapshot provided to the selector function can also be undefined:

    const count = useSelector(maybeActor, (snapshot) => {
      // `snapshot` may be undefined
      return snapshot?.context.count;
    });
    
    count; // number | undefined
    
xstate - @xstate/[email protected]

Published by github-actions[bot] 8 months ago

Minor Changes

  • #4231 c2402e7bc Thanks @davidkpiano! - The actor passed to useSelector(actor, selector) is now allowed to be undefined for an actor that may not exist yet. For actors that may be undefined, the snapshot provided to the selector function can also be undefined:

    const count = useSelector(maybeActor, (snapshot) => {
      // `snapshot` may be undefined
      return snapshot?.context.count;
    });
    
    count; // number | undefined
    
xstate - [email protected]

Published by github-actions[bot] 8 months ago

Patch Changes

  • #4731 960cdcbcb Thanks @davidkpiano! - You can now import getInitialSnapshot(…) from xstate directly, which is useful for getting a mock of the initial snapshot when interacting with machines (or other actor logic) without createActor(…):

    import { getInitialSnapshot } from 'xstate';
    import { someMachine } from './someMachine';
    
    // Returns the initial snapshot (state) of the machine
    const initialSnapshot = getInitialSnapshot(
      someMachine,
      { name: 'Mateusz' } // optional input
    );
    
xstate - [email protected]

Published by github-actions[bot] 9 months ago

Patch Changes

xstate - [email protected]

Published by github-actions[bot] 9 months ago

Minor Changes

  • #4704 78699aef6 Thanks @Andarist! - createActor will now error if the required input is not given to it.

  • #4688 14902e17a Thanks @Andarist! - The schemas property in setup(...) is now passed through to the resulting machine. This property is meant to be used with future developer tooling, and is typed as unknown for now.

Patch Changes

xstate - [email protected]

Published by github-actions[bot] 9 months ago

Patch Changes

  • #4685 e43eab144 Thanks @davidkpiano! - State IDs that have periods in them are now supported if those periods are escaped.

    The motivation is that external tools, such as Stately Studio, may allow users to enter any text into the state ID field. This change allows those tools to escape periods in state IDs, so that they don't conflict with the internal path-based state IDs.

    E.g. if a state ID of "Loading..." is entered into the state ID field, instead of crashing either the external tool and/or the XState state machine, it should be converted by the tool to "Loading\\.\\.\\.", and those periods will be ignored by XState.

xstate - @xstate/[email protected]

Published by github-actions[bot] 9 months ago

Patch Changes

  • #4695 52900a084 Thanks @davidkpiano! - Options in createActorContext are now properly merged with provider options. Previously, provider options replaced the actor options.

    const { inspect } = createBrowserInspector();
    
    const SomeContext = createActorContext(someMachine, { inspect });
    
    // ...
    // Options are now merged:
    // { inspect: inspect, input: 10 }
    <SomeContext.Provider options={{ input: 10 }}>
      {/* ... */}
    </SomeContext.Provider>;
    
xstate - @xstate/[email protected]

Published by github-actions[bot] 9 months ago

Minor Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] 9 months ago

Minor Changes

Patch Changes

xstate - [email protected]

Published by github-actions[bot] 9 months ago

Patch Changes

xstate - [email protected]

Published by github-actions[bot] 9 months ago

Minor Changes

  • #4596 6113a590a Thanks @davidkpiano! - Introduce getNextSnapshot(...), which determines the next snapshot for the given actorLogic based on the given snapshot and event.

    If the snapshot is undefined, the initial snapshot of the actorLogic is used.

    import { getNextSnapshot } from 'xstate';
    import { trafficLightMachine } from './trafficLightMachine.ts';
    
    const nextSnapshot = getNextSnapshot(
      trafficLightMachine, // actor logic
      undefined, // snapshot (or initial state if undefined)
      { type: 'TIMER' }
    ); // event object
    
    console.log(nextSnapshot.value);
    // => 'yellow'
    
    const nextSnapshot2 = getNextSnapshot(
      trafficLightMachine, // actor logic
      nextSnapshot, // snapshot
      { type: 'TIMER' }
    ); // event object
    
    console.log(nextSnapshot2.value);
    // =>'red'
    

Patch Changes

  • #4659 1ae07f5bf Thanks @Andarist! - Allow event in transitions to be narrowed down even when its .type is defined using a union.
xstate - @xstate/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

xstate - [email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

xstate - [email protected]

Published by github-actions[bot] 10 months ago

Minor Changes

  • #4616 e8c0b15b2 Thanks @Andarist! - context factories receive self now so you can immediately pass that as part of the input to spawned actors.

    setup({
      /* ... */
    }).createMachine({
      context: ({ spawn, self }) => {
        return {
          childRef: spawn('child', { input: { parent: self } })
        };
      }
    });
    
xstate - [email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

  • #4597 ae0b05f11 Thanks @davidkpiano! - Update the argument object of enqueueActions(...) to include the self and system properties:

    // ...
    entry: enqueueActions(({ self, system }) => {
      // ...
    });
    
xstate - @xstate/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

  • #4604 3ad929eb4 Thanks @tkofh! - The useActor hook now correctly types it's send function when passed an ActorLogic.