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

Typescript support #18

Open
mattbradbury opened this issue Mar 31, 2018 · 2 comments
Open

Typescript support #18

mattbradbury opened this issue Mar 31, 2018 · 2 comments

Comments

@mattbradbury
Copy link

Would be awesome to have Typescript definitions.

@krasimir
Copy link
Owner

Yeah ... that will be really nice. Unfortunately I have 0 experience with TypeScript. PRs are of course welcome.

@mateusvahl
Copy link

I've possible to add your own types, here an example:

// Transitions:
export enum SCREENS {
  IDLE = "screen_idle",
  LOGIN_DETAILS = "screen_login_details",
}

// Machine State
type MachineState = {
  name: SCREENS;
  step: number;
};

// Machine interface
export interface MachineProps {
  name: string;
  state: MachineState;
  isScreenLoginDetails: () => boolean;
  isScreenIdle: () => boolean;
  advance: () => null;
}

// Your methods
export const advance = (machine: MachineProps): MachineState => {
 // Return the new state...
  return state;
};

// Constructor
export const makeMachine = (): MachineProps => {
  const initialState: MachineState = {
    name: SCREENS.IDLE,
    step: 1
  };

  return Machine.create("my-machine-name", {
    state: initialState,
    transitions: {
      [SCREENS.IDLE]: {
        advance,
      },
      [SCREENS.LOGIN_DETAILS]: {
       // ...
      },
    },
  });
};

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

3 participants