Skip to content
Compare
Choose a tag to compare
@github-actions github-actions released this 16 Sep 15:08
· 13 commits to main since this release
571e266

Minor Changes

  • #5064 84aca37d0b02cb9cd5a32c8fd09e487bd8fe2a47 Thanks @davidkpiano! - There is a new single-argument config API for createStore(config):

    const store = createStore({
      // Types (optional)
      types: {
        emitted: {} as { type: 'incremented' }
      },
    
      // Context
      context: { count: 0 },
    
      // Transitions
      on: {
        inc: (context, event: { by: number }, enq) => {
          enq.emit({ type: 'incremented' });
    
          return { count: context.count + event.by };
        },
        dec: (context, event: { by: number }) => ({
          count: context.count - event.by
        })
      }
    });
  • #5064 84aca37d0b02cb9cd5a32c8fd09e487bd8fe2a47 Thanks @davidkpiano! - You can now emit events from a store:

    import { createStore } from '@xstate/store';
    
    const store = createStore({
      context: {
        count: 0
      },
      on: {
        increment: (context, event, { emit }) => {
          emit({ type: 'incremented' });
          return { count: context.count + 1 };
        }
      }
    });
    
    store.on('incremented', () => {
      console.log('incremented!');
    });