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

[core] Remove context from StateNodeConfig interface #2422

Merged
merged 3 commits into from
Jul 31, 2021

Conversation

davidkpiano
Copy link
Member

The context property has been removed from StateNodeConfig, as it has never been allowed, nor has it ever done anything. The previous typing was unsafe and allowed context to be specified on nested state nodes:

createMachine({
  context: {
    /* ... */
  }, // ✅ This is allowed
  initial: 'inner',
  states: {
    inner: {
      context: {
        /* ... */
      } // ❌ This will no longer compile
    }
  }
});

@davidkpiano davidkpiano merged commit f2d8604 into main Jul 31, 2021
@davidkpiano davidkpiano deleted the davidkpiano/no-context-on-state branch July 31, 2021 16:51
@github-actions github-actions bot mentioned this pull request Jul 31, 2021
@@ -291,7 +292,9 @@ class StateNode<
*/
private _context:
| Readonly<TContext>
| (() => Readonly<TContext>) = config.context as any // TODO: this is unsafe, but we're removing it in v5 anyway
| (() => Readonly<TContext>) = ('context' in config
? (config as StateMachine<TContext, any, TEvent>).context
Copy link
Member

Choose a reason for hiding this comment

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

This has tripped me a little bit. I know it will be a subject of a refactor in v5 so it doesn't matter - just want to leave a short comment for posterity.

The context has been removed from StateNodeConfig so I was wondering how this cast has produced a type that had a context property. StateMachine extends the StateNode class (and not the StateNodeConfig interface) which still has a context property:

public get context(): TContext {

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.

2 participants