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

Events do not show up if they exist in another file. #23

Open
cpetzel opened this issue Nov 14, 2021 · 1 comment
Open

Events do not show up if they exist in another file. #23

cpetzel opened this issue Nov 14, 2021 · 1 comment

Comments

@cpetzel
Copy link

cpetzel commented Nov 14, 2021

I often create a machine.types.tsx file that contains all of my states, events, and the type of machine. I then use these values/enums in separate machines based on platform...

Example...
exampleMachine.types.tsx - exports enums for States, types for events, and the type of the machine.

export enum Events {
  event1 = 'EVENT_1',
  event2 = 'EVENT_12',
  ....
}

type EventTypeSchema =
  | Events.event1
  | Events.event2;

export interface MyMachineEvents extends EventObject {
  type: EventTypeSchema;
}

export interface MachineContext {}

export type TMyMachine = StateMachine<
  MachineContext,
  any,
  MyMachineEvents
>;

exampleMachine.native.tsx - This will actually create the machine for iOS and Android (react native) that was typed in exampleMachine.types.tsx, utilizing the States enum from the same file.

exampleMachine.web.tsx - This will actually create the machine for web that was typed in exampleMachine.types.tsx, utilizing the States enum from the same file. This machine may behave a bit differently, because it is on another platform, but it still adheres to the same contract/types, so any parent machine that "uses" it has type safety.

Issue

The visualizer is not drawing the events because the parser doesn't know about them, because they live in another file.

Would it be possible to extend the functionality of the xstate-parser to search import paths for these events/states?

Thanks so much for the wonderful tool!

@mattpocock
Copy link
Contributor

Thanks for the detailed issue! This PR (statelyai/xstate-parser#11) would solve this.

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

No branches or pull requests

2 participants