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

[v5] Remove Typestate #2876

Merged
merged 4 commits into from
Dec 15, 2021
Merged

[v5] Remove Typestate #2876

merged 4 commits into from
Dec 15, 2021

Conversation

davidkpiano
Copy link
Member

This PR removes Typestate typings from XState core.

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2021

🦋 Changeset detected

Latest commit: b00e065

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

This PR includes changesets to release 8 packages
Name Type
xstate Major
@xstate/graph Major
@xstate/immer Major
@xstate/inspect Major
@xstate/react Major
@xstate/svelte Major
@xstate/test Major
@xstate/vue Major

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

@davidkpiano davidkpiano changed the base branch from main to next December 12, 2021 19:35
@tonivj5
Copy link

tonivj5 commented Dec 15, 2021

Hey, I'm starting to use xstate on backend and I'm recently discovered TypeStates. I was looking for some way to define a concrete state of the context on an determined state point... Seeing this PR, I wonder what is the new way to do it?

@Andarist
Copy link
Member

I wonder what is the new way to do it?

There is no new way to do it. What is being removed in this PR wasn't quite type-safe and we have to think about other ways to achieve this, this time in a type-safe manner.

davidkpiano and others added 2 commits December 15, 2021 04:09
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@ghost
Copy link

ghost commented Dec 15, 2021

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

@davidkpiano
Copy link
Member Author

Hey, I'm starting to use xstate on backend and I'm recently discovered TypeStates. I was looking for some way to define a concrete state of the context on an determined state point... Seeing this PR, I wonder what is the new way to do it?

Like @Andarist said, we're currently figuring it out. One idea is to use a design-by-contract approach so that you can guarantee that certain conditions hold in a state:

// idea
states: {
  loading: {
    invoke: {
      src: 'loadUser',
      onDone: { target: 'loaded', actions: assign({ user: (_, e) => e.data }) }
    }
  },
  loaded: {
    // precondition - assert this is true whenever entering this state
    pre: (ctx) => !!ctx.user // in this state, the `user` should always exist
    // ...
  }
}

Then, a typegen can derive that in loaded, ctx.user will exist.

@davidkpiano davidkpiano merged commit f85fdba into next Dec 15, 2021
@davidkpiano davidkpiano deleted the v5/remove-typestate branch December 15, 2021 12:13
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.

None yet

3 participants