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

Passed state type generic to the Config interface #1122

Merged
merged 2 commits into from
Apr 11, 2020
Merged

Passed state type generic to the Config interface #1122

merged 2 commits into from
Apr 11, 2020

Conversation

chaance
Copy link
Contributor

@chaance chaance commented Apr 10, 2020

The StateMachine.Config interface should accept a third generic for our state type, which should then be provided when used in the createMachine function. I think. I have declared my own module and haven't had any issues, but if there are any reasons this wasn't set up this way originally let me know.

Using the state type provides helpful intellisense when defining the state chart transitions!

NOTE: I ran tests locally but a bunch of them failed because local modules weren't resolved. Not sure if there is a step missing in CONTRIBUTING.md to link these packages.

@changeset-bot
Copy link

changeset-bot bot commented Apr 10, 2020

🦋 Changeset is good to go

Latest commit: c745df0

We got this.

This PR includes changesets to release 1 package
Name Type
@xstate/fsm 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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 10, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c745df0:

Sandbox Source
zen-antonelli-dm9iv Configuration
blazing-water-1iu0k Configuration

@@ -81,7 +81,7 @@ export function createMachine<
TEvent extends EventObject = EventObject,
TState extends Typestate<TContext> = any
>(
fsmConfig: StateMachine.Config<TContext, TEvent>,
fsmConfig: StateMachine.Config<TContext, TEvent, TState>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to open a discussion: XState core always uses <Context, State, Event> so I'm not sure if @davidkpiano and @Andarist would be okay with the xstate-fsm API to differ. In this case, it would obviously be a breaking change to decide in favor of consistency by having the type arguments in the same order as within the core.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TState is already the third argument in the State and Machine interfaces in fsm, so this PR follows those patterns. Since TState defaults to any this shouldn't be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodingDive Moving forward in V5, the generic arguments will always follow <TContext, TEvent, ...> in that order.

Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
@davidkpiano davidkpiano merged commit feba33d into statelyai:master Apr 11, 2020
This was referenced Apr 11, 2020
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.

4 participants