Last active
December 3, 2019 17:15
-
-
Save schpet/7b560bf41d1ecf7531f778e0117ca2f1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const generationSucceeded = (c, e) => { | |
| return e.generationResult && e.generationResult.ok | |
| } | |
| const generationStates = { | |
| initial: "initial", | |
| states: { | |
| initial: { | |
| on: { | |
| GENERATE: [ | |
| { | |
| target: "generated", | |
| // Only transition to 'searching' if the guard (cond) evaluates to true | |
| cond: generationSucceeded, | |
| }, | |
| { target: "generationError" }, | |
| ], | |
| }, | |
| }, | |
| generationError: {}, | |
| generated: {}, | |
| }, | |
| } | |
| const commandMachine = Machine( | |
| { | |
| id: "command", | |
| initial: "invoked", | |
| context: { | |
| mode: undefined, | |
| workspace: undefined, // where tromp.json and commands are run relative to | |
| configError: undefined, | |
| }, | |
| states: { | |
| invoked: { | |
| entry: [], | |
| on: { | |
| EXECUTE: { | |
| target: "complete", | |
| actions: [ | |
| // TODO: consider storing "previous command" to state | |
| ], | |
| }, | |
| NO_COMMAND: { | |
| target: "noCommand", // TODO: assign the current filename | |
| actions: assign({ | |
| // @ts-ignore | |
| workspace: (_ctx, ev) => ev.workspace, | |
| }), | |
| }, | |
| CONFIG_MISSING: { | |
| target: "configurationMissing", | |
| actions: assign({ | |
| // @ts-ignore | |
| workspace: (_ctx, ev) => ev.workspace, | |
| }), | |
| }, | |
| CONFIG_ERROR: { | |
| target: "configurationError", | |
| actions: assign({ | |
| // @ts-ignore | |
| configError: (_ctx, ev) => ev.configError, | |
| // @ts-ignore | |
| workspace: (_ctx, ev) => ev.workspace, | |
| }), | |
| }, | |
| NO_WORKSPACE: "noWorkspace", | |
| }, | |
| }, | |
| noCommand: { | |
| on: { | |
| DISMISS: "complete", | |
| EDIT: "edit", | |
| }, | |
| }, | |
| configurationMissing: { | |
| on: { | |
| GENERATE: "generating", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| configurationError: { | |
| on: { | |
| EDIT: "edit", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| edit: { | |
| entry: "EDIT_CONFIG", | |
| on: { | |
| "": "complete", | |
| }, | |
| }, | |
| generating: { | |
| entry: ["GENERATE_CONFIG"], | |
| ...generationStates, | |
| }, | |
| noWorkspace: { | |
| on: { | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| complete: { | |
| type: "final", | |
| }, | |
| }, | |
| }, | |
| { | |
| guards: { | |
| generationSucceeded, | |
| }, | |
| } | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment