github statelyai/xstate xstate@4.23.2

2 years ago

Patch Changes

  • 6c3f15c9 #2551 Thanks @mattpocock! - Widened the *From utility types to allow extracting from factory functions.

    This allows for:

    const makeMachine = () => createMachine({});
    
    type Interpreter = InterpreterFrom<typeof makeMachine>;
    type Actor = ActorRefFrom<typeof makeMachine>;
    type Context = ContextFrom<typeof makeMachine>;
    type Event = EventsFrom<typeof makeMachine>;

    This also works for models, behaviours, and other actor types.

    The previous method for doing this was a good bit more verbose:

    const makeMachine = () => createMachine({});
    
    type Interpreter = InterpreterFrom<ReturnType<typeof machine>>;
  • 413a4578 #2491 Thanks @davidkpiano! - The custom .toString() method on action objects is now removed which improves performance in larger applications (see #2488 for more context).

  • 5e1223cd #2422 Thanks @davidkpiano! - The context property has been removed from StateNodeConfig, as it has never been allowed, nor has it ever done anything. The previous typing was unsafe and allowed context to be specified on nested state nodes:

    createMachine({
      context: {
        /* ... */
      }, // ✅ This is allowed
      initial: 'inner',
      states: {
        inner: {
          context: {
            /* ... */
          } // ❌ This will no longer compile
        }
      }
    });
  • 5b70c2ff #2508 Thanks @davidkpiano! - A race condition occurred when a child service is immediately stopped and the parent service tried to remove it from its undefined state (during its own initialization). This has been fixed, and the race condition no longer occurs. See this issue for details.

  • 5a9500d1 #2522 Thanks @farskid, @Andarist! - Adjusted TS type definitions of the withContext and withConfig methods so that they accept "lazy context" now.

    Example:

    const copy = machine.withContext(() => ({
      ref: spawn(() => {})
    }));
  • 84f9fcae #2540 Thanks @Andarist! - Fixed an issue with state.hasTag('someTag') crashing when the state was rehydrated.

  • c17dd376 #2496 Thanks @VanTanev! - Add utility type EmittedFrom<T> that extracts Emitted type from any type which can emit data

Don't miss a new xstate release

NewReleases is sending notifications on new releases.