-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
🦋 Changeset detectedLatest commit: b87be16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
👇 Click on the image for a new way to code review
Legend |
interpreterOptions?: InterpreterOptions, | ||
observerOrListener?: | ||
| Observer<StateFrom<TMachine>> | ||
| ((value: StateFrom<TMachine>) => void) |
There was a problem hiding this comment.
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:
xstate/packages/xstate-react/test/createActorContext.test.tsx
Lines 307 to 338 in 6f15b2c
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); | |
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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:
|
}: { | ||
children: React.ReactNode; | ||
machine: TMachine | (() => TMachine); | ||
options?: any; |
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😬)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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 😅
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. |
fixes #3811