Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version Packages #5076

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Version Packages #5076

merged 1 commit into from
Sep 16, 2024

Conversation

github-actions[bot]
Copy link
Contributor

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

Releases

@xstate/[email protected]

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!');
    });

@davidkpiano davidkpiano merged commit 9d0c1e1 into main Sep 16, 2024
@davidkpiano davidkpiano deleted the changeset-release/main branch September 16, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant