Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Putting machine options in separate files? #91

Open
PickleyD opened this issue Jul 4, 2021 · 1 comment
Open

Putting machine options in separate files? #91

PickleyD opened this issue Jul 4, 2021 · 1 comment

Comments

@PickleyD
Copy link

PickleyD commented Jul 4, 2021

I'd like to be able to define my machine options in separate files so I can swap out real/mock service implementations like the following:

interface HomePageProviderProps {
    machineOptions: any; // <-- How do I type this?
    children: React.ReactNode;
}

const HomePageProvider = ({ machineOptions, children }: HomePageProviderProps) => {

    const [state, send] = useMachine(homePageMachine, machineOptions)

    return <HomePageStateContext.Provider value={state}>
        <HomePageDispatchContext.Provider value={{}}>
            {children}
        </HomePageDispatchContext.Provider>
    </HomePageStateContext.Provider>
}

Is there an easy way to get the generated types for my machine options so I can replace this any?

@PickleyD PickleyD changed the title Splitting machine options into separate files? Putting machine options in separate files? Jul 4, 2021
@PickleyD
Copy link
Author

PickleyD commented Jul 5, 2021

Replacing any with HomePageMachineStateMachine<HomePageMachineContext, HomePageMachineEvent, "homePageMachine">["_options"] seems to do the job. I'm fine with this unless there is a more reader-friendly way of doing it which I'm overlooking.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant