Xstate Versions Save

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

@xstate/[email protected]

4 months ago

Patch Changes

[email protected]

4 months ago

Minor Changes

  • #4750 a9e3c086f Thanks @Andarist! - Revamped setup and actions types to disallow usage of non-configured implementations

@xstate/[email protected]

4 months ago

Minor Changes

  • #3727 5fb3c68 Thanks @Andarist! - exports field has been added to the package.json manifest. It limits what files can be imported from a package - it's no longer possible to import from files that are not considered to be a part of the public API.

  • #4265 1153b3f Thanks @davidkpiano! - FSM-related functions have been removed.

  • #4748 d73ac8e48 Thanks @Andarist! - The createService(machine) hook has been removed; use the useActorRef(logic) hook instead.

  • #4748 d73ac8e48 Thanks @Andarist! - The fromActorRef(actorRef) has been added. You can use it to get an accessor for reactive snapshot of any existing actorRef.

  • #4748 d73ac8e48 Thanks @Andarist! - The useActor hook accepts an actor logic now and not an existing actorRef. It's used to creating a new instance of an actor and it works just like useMachine used to work (useMachine is now just an alias of useActor).

[email protected]

4 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.

[email protected]

4 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/[email protected]

4 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]

4 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
    

[email protected]

4 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
    );
    

[email protected]

4 months ago

Patch Changes

[email protected]

5 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