statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
27.23k stars 1.26k forks source link

[@xstate/store] Add examples + update `createStoreWithProducer(…)` #5079

Closed davidkpiano closed 2 months ago

davidkpiano commented 2 months ago

The createStoreWithProducer(…) function now uses the new configuration API:

import { createStoreWithProducer } from '@xstate/store';
// DEPRECATED API
// const store = createStoreWithProducer(
//   producer,
//   {
//     count: 0
//   },
//   {
//     inc: (context, event) => {
//       context.count++;
//     }
//   }
// );

const store = createStoreWithProducer(producer, {
  context: {
    count: 0
  },
  on: {
    inc: (context, event) => {
      context.count++;
    }
  }
});

Also, an example directory and simple example was added.

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: ee56fe133a91cafdd495312f9847292b79a6eb21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages | Name | Type | | -------------- | ----- | | xstate | Patch | | @xstate/store | Minor | | @xstate/graph | Patch | | @xstate/react | Patch | | @xstate/solid | Patch | | @xstate/svelte | Patch | | @xstate/vue | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

boneskull commented 1 month ago

Should type changes like this be considered breaking? It does break my build

davidkpiano commented 1 month ago

Should type changes like this be considered breaking? It does break my build

We try to minimize breaking type changes but they are considered minor changes for XState, just like in TS: https://github.com/statelyai/xstate?tab=readme-ov-file#typescript-changes