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

Tweak what options are accepted by createActorContext and where #3814

Merged
merged 5 commits into from
Feb 10, 2023

Conversation

Andarist
Copy link
Member

@Andarist Andarist commented Feb 7, 2023

fixes #3811

@changeset-bot
Copy link

changeset-bot bot commented Feb 7, 2023

🦋 Changeset detected

Latest commit: b87be16

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

This PR includes changesets to release 1 package
Name Type
@xstate/react Minor

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

@ghost
Copy link

ghost commented Feb 7, 2023

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Comment on lines +19 to +22
interpreterOptions?: InterpreterOptions,
observerOrListener?:
| Observer<StateFrom<TMachine>>
| ((value: StateFrom<TMachine>) => void)
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a little bit of a breaking change for this test case:

it('should be able to pass interpreter options to the actor', () => {
const someMachine = createMachine({
initial: 'a',
states: {
a: {
entry: ['testAction']
}
}
});
const stubFn = jest.fn();
const SomeContext = createActorContext(someMachine, {
actions: {
testAction: stubFn
}
});
const Component = () => {
return null;
};
const App = () => {
return (
<SomeContext.Provider machine={someMachine}>
<Component />
</SomeContext.Provider>
);
};
render(<App />);
expect(stubFn).toHaveBeenCalledTimes(1);
});

Copy link
Member Author

Choose a reason for hiding this comment

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

just rechecking - are we OK with this 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.

Yes; options was in the wrong place

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 7, 2023

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

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

}: {
children: React.ReactNode;
machine: TMachine | (() => TMachine);
options?: any;
Copy link
Member Author

Choose a reason for hiding this comment

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

I used any for simplicity here since the return type of createActorContext is explicitly typed and I didn't want to include the typegen-related monster in both places here. I think that we could drop the explicit return type from there, annotate things in the body and let TS to infer things here. This way each signature would only have to live in one place

@@ -85,36 +85,35 @@ export function useIdleInterpreter(
return service as any;
}

export type RestParams<
Copy link
Member Author

Choose a reason for hiding this comment

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

I just removed export here

props: {
children: React.ReactNode;
machine?: TMachine | (() => TMachine);
} & (AreAllImplementationsAssumedToBeProvided<
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we have the simpler type here? At least without AreAllImplementationsAssumedToBeProvided

Copy link
Member Author

Choose a reason for hiding this comment

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

The added type-oriented tests wouldn't pass. It's quite nice that we validate if the user has configured all implementations or not (the cost for that is the readability of those types though 😬)

Copy link
Member

@davidkpiano davidkpiano left a comment

Choose a reason for hiding this comment

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

Spooky types:

CleanShot 2023-02-08 at 21 32 53@2x

Copy link
Member

@davidkpiano davidkpiano left a comment

Choose a reason for hiding this comment

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

The types are a little questionable, but LGTM 😅

@Andarist
Copy link
Member Author

Andarist commented Feb 9, 2023

Spooky types:

I agree that those types don't have the best display in the IDE. It's not a new problem with our types though. I will keep thinking about how this can be fixed - it is quite hard with those kinds of types.

@Andarist Andarist merged commit 494203b into main Feb 10, 2023
@Andarist Andarist deleted the andarist/tweak-create-actor-context-types branch February 10, 2023 14:55
@github-actions github-actions bot mentioned this pull request Feb 10, 2023
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.

Bug: useActorContext type issues
2 participants