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

setup().extend() #4703

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

setup().extend() #4703

wants to merge 4 commits into from

Conversation

davidkpiano
Copy link
Member

No description provided.

Copy link

changeset-bot bot commented Jan 24, 2024

⚠️ No Changeset found

Latest commit: eae625c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

codesandbox-ci bot commented Jan 24, 2024

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 eae625c:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

@@ -203,17 +163,171 @@ export function setup<
TTag
>
>;
} {

extend: <
Copy link
Member

@Andarist Andarist Jan 24, 2024

Choose a reason for hiding this comment

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

extend can't be used to add event types, context types, etc. This should only support actions, actors, guards and delays

The problem is that this would become possible and incorrect:

setup({
  types: {} as { events: { type: 'FOO' } },
  actions: {
    doStuff: ({ event }) => {} // sees `{ type: 'FOO' }`
  }
}).extend({
  types: {} as { events: { type: 'BAR' } }, 
}).createMachine({
  initial: 'a',
  states: {
    a: {
      on: { BAR: 'b' }
    },
    b: {
      entry: 'doStuff' // oops, it got called with `{ type: 'BAR' }`
    }
  }
})

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, that's fair

Copy link
Member

Choose a reason for hiding this comment

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

setup({})
  .extend({
    actions: {
      doOneStuff: () => {},
    },
  })
  .createMachine({
    entry: "doOtherStuff", // this should be an error
  });

That's why I've mentioned on Discord that before doing this change we need to make it impossible to use non-implemented things when nothing was implemented in that "group".

Copy link
Member

Choose a reason for hiding this comment

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

I have a draft for this change here but I didn't have time to finish it

Comment on lines +195 to +198
ToProvidedActor<TExtChildrenMap, TExtActors>,
ToParameterizedObject<TExtActions>,
ToParameterizedObject<TExtGuards>,
TExtDelay
Copy link
Member

Choose a reason for hiding this comment

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

all those locations should be unions with their respective "outer" parameters, the same goes for guars and delays

Copy link
Member

Choose a reason for hiding this comment

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

and in a similar manner, it's very likely that those nevers should be converted to their respective "outer" type parameters:


the defaults for those should still be never - the first call in a chain doesn't have any outer type parameters after all

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

2 participants