Skip to content

Releases: statelyai/xstate

@xstate/[email protected]

21 Feb 10:53
e7ed2cd
Compare
Choose a tag to compare

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]

17 Feb 13:32
a09d8f2
Compare
Choose a tag to compare

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]

16 Feb 14:50
0eca5ad
Compare
Choose a tag to compare

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]

12 Feb 23:35
b5d40d8
Compare
Choose a tag to compare

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]

12 Feb 23:35
b5d40d8
Compare
Choose a tag to compare

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]

07 Feb 16:45
91549ce
Compare
Choose a tag to compare

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]

05 Feb 22:25
54a2b01
Compare
Choose a tag to compare

Patch Changes

[email protected]

29 Jan 13:07
bee9f77
Compare
Choose a tag to compare

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

[email protected]

23 Jan 17:22
cc5c67e
Compare
Choose a tag to compare

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

23 Jan 17:22
cc5c67e
Compare
Choose a tag to compare

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