Skip to content

Releases: statelyai/xstate

xstate@5.12.0

24 Apr 19:45
a67e99f
Compare
Choose a tag to compare

Minor Changes

  • #4863 0696adc21 Thanks @davidkpiano! - Meta objects for state nodes and transitions can now be specified in setup({ types: … }):

    const machine = setup({
      types: {
        meta: {} as {
          layout: string;
        }
      }
    }).createMachine({
      initial: 'home',
      states: {
        home: {
          meta: {
            layout: 'full'
          }
        }
      }
    });
    
    const actor = createActor(machine).start();
    
    actor.getSnapshot().getMeta().home;
    // => { layout: 'full' }
    // if in "home" state

@xstate/vue@3.1.2

17 Apr 00:46
a36e3ec
Compare
Choose a tag to compare

Patch Changes

  • #4844 5aa6eb05c Thanks @davidkpiano! - The useSelector(…) hook from @xstate/react is now compatible with stores from @xstate/store.

    import { createStore } from '@xstate/store';
    import { useSelector } from '@xstate/react';
    
    const store = createStore(
      {
        count: 0
      },
      {
        inc: {
          count: (context) => context.count + 1
        }
      }
    );
    
    function Counter() {
      // Note that this `useSelector` is from `@xstate/react`,
      // not `@xstate/store/react`
      const count = useSelector(store, (state) => state.context.count);
    
      return (
        <div>
          <button onClick={() => store.send({ type: 'inc' })}>{count}</button>
        </div>
      );
    }

@xstate/svelte@3.0.3

17 Apr 00:46
a36e3ec
Compare
Choose a tag to compare

Patch Changes

  • #4844 5aa6eb05c Thanks @davidkpiano! - The useSelector(…) hook from @xstate/react is now compatible with stores from @xstate/store.

    import { createStore } from '@xstate/store';
    import { useSelector } from '@xstate/react';
    
    const store = createStore(
      {
        count: 0
      },
      {
        inc: {
          count: (context) => context.count + 1
        }
      }
    );
    
    function Counter() {
      // Note that this `useSelector` is from `@xstate/react`,
      // not `@xstate/store/react`
      const count = useSelector(store, (state) => state.context.count);
    
      return (
        <div>
          <button onClick={() => store.send({ type: 'inc' })}>{count}</button>
        </div>
      );
    }

@xstate/react@4.1.1

17 Apr 00:46
a36e3ec
Compare
Choose a tag to compare

Patch Changes

  • #4844 5aa6eb05c Thanks @davidkpiano! - The useSelector(…) hook from @xstate/react is now compatible with stores from @xstate/store.

    import { createStore } from '@xstate/store';
    import { useSelector } from '@xstate/react';
    
    const store = createStore(
      {
        count: 0
      },
      {
        inc: {
          count: (context) => context.count + 1
        }
      }
    );
    
    function Counter() {
      // Note that this `useSelector` is from `@xstate/react`,
      // not `@xstate/store/react`
      const count = useSelector(store, (state) => state.context.count);
    
      return (
        <div>
          <button onClick={() => store.send({ type: 'inc' })}>{count}</button>
        </div>
      );
    }

xstate@5.11.0

16 Apr 14:31
9118720
Compare
Choose a tag to compare

Minor Changes

  • #4806 f4e0ec48c Thanks @davidkpiano! - Inline actor logic is now permitted when named actors are present. Defining inline actors will no longer cause a TypeScript error:

    const machine = setup({
      actors: {
        existingActor: fromPromise(async () => {
          // ...
        })
      }
    }).createMachine({
      invoke: {
        src: fromPromise(async () => {
          // Inline actor
        })
        // ...
      }
    });

xstate@5.10.0

09 Apr 14:41
0ce95c2
Compare
Choose a tag to compare

Minor Changes

  • #4822 f7f1fbbf3 Thanks @davidkpiano! - The clock and logger specified in the options object of createActor(logic, options) will now propagate to all actors created within the same actor system.

    import { setup, log, createActor } from 'xstate';
    
    const childMachine = setup({
      // ...
    }).createMachine({
      // ...
      // Uses custom logger from root actor
      entry: log('something')
    });
    
    const parentMachine = setup({
      // ...
    }).createMachine({
      // ...
      invoke: {
        src: childMachine
      }
    });
    
    const actor = createActor(parentMachine, {
      logger: (...args) => {
        // custom logger for args
      }
    });
    
    actor.start();

@xstate/store@0.0.3

09 Apr 20:28
424ce97
Compare
Choose a tag to compare

Patch Changes

@xstate/store@0.0.2

07 Apr 13:21
158eca6
Compare
Choose a tag to compare

Patch Changes

  • #4752 8a32374e7 Thanks @davidkpiano! - Initial release of @xstate/store

    import { createStore } from '@xstate/store';
    
    const store = createStore(
      // initial context
      { count: 0, greeting: 'hello' },
      // transitions
      {
        inc: {
          count: (context) => context.count + 1
        },
        updateBoth: {
          count: () => 42,
          greeting: 'hi'
        }
      }
    );
    
    store.send({
      type: 'inc'
    });
    
    console.log(store.getSnapshot());
    // Logs:
    // {
    //   status: 'active',
    //   context: {
    //     count: 1,
    //     greeting: 'hello'
    //   }
    // }

xstate@5.9.1

02 Mar 22:55
839162d
Compare
Choose a tag to compare

Patch Changes

xstate@5.9.0

01 Mar 19:26
0d4663d
Compare
Choose a tag to compare

Minor Changes

  • #4746 b570ba20d Thanks @davidkpiano! - The new emit(…) action creator emits events that can be received by listeners. Actors are now event emitters.

    import { emit } from 'xstate';
    
    const machine = createMachine({
      // ...
      on: {
        something: {
          actions: emit({
            type: 'emitted',
            some: 'data'
          })
        }
      }
      // ...
    });
    
    const actor = createActor(machine).start();
    
    actor.on('emitted', (event) => {
      console.log(event);
    });
    
    actor.send({ type: 'something' });
    // logs:
    // {
    //   type: 'emitted',
    //   some: 'data'
    // }
  • #4777 4abeed9df Thanks @Andarist! - Added support for params to enqueueActions