Created
January 14, 2020 05:51
-
-
Save schpet/5fb7db5f2c5a50c69c8b9c1a6dae8010 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 configMachine = Machine({ | |
| id: "config", | |
| initial: "initial", | |
| strict: true, | |
| context: { | |
| workspace: undefined, | |
| errorMessage: undefined, | |
| config: undefined, | |
| }, | |
| states: { | |
| initial: { | |
| invoke: { | |
| src: "getWorkspace", | |
| onDone: { | |
| target: "inWorkspace", | |
| actions: assign({ | |
| workspace: (_context, event) => event.data, | |
| }), | |
| }, | |
| onError: "noWorkspace", | |
| }, | |
| }, | |
| inWorkspace: { | |
| invoke: { | |
| src: "getConfig", | |
| onDone: { | |
| target: "complete", | |
| actions: assign({ | |
| config: (_context, event) => { | |
| return event.data; | |
| }, | |
| }), | |
| }, | |
| onError: [ | |
| { | |
| target: "configNotFound", | |
| cond: function configNotFound(_context, event) { | |
| return event.data && event.data.problem === "config_not_found"; | |
| }, | |
| actions: assign({ | |
| // TODO types | |
| errorMessage: (_context, event) => event.data.message, | |
| }), | |
| }, | |
| { | |
| target: "configInvalid", | |
| cond: function configInvalid(_context, event) { | |
| return event.data && event.data.problem === "config_invalid"; | |
| }, | |
| actions: assign({ | |
| errorMessage: (_context, event) => event.data.message, | |
| }), | |
| }, | |
| ], | |
| }, | |
| }, | |
| configNotFound: { | |
| invoke: { src: "renderConfigNotFound" }, | |
| on: { | |
| GENERATE: "generating", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| configInvalid: { | |
| invoke: { src: "renderConfigInvalid" }, | |
| on: { | |
| EDIT: "edit", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| edit: { | |
| entry: "EDIT_CONFIG", | |
| on: { | |
| "": "complete", | |
| }, | |
| }, | |
| generating: { | |
| invoke: { | |
| id: "generateConfig", | |
| src: "generateConfig", | |
| onDone: "complete", | |
| onError: "generationFailed", | |
| }, | |
| }, | |
| generationFailed: { | |
| invoke: { src: "renderGenerationFailed" }, | |
| on: { | |
| // RETRY: "generating", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| noWorkspace: { | |
| invoke: { src: "renderNoWorkspace" }, | |
| on: { | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| noEditor: { | |
| invoke: { src: "renderNoEditor" }, | |
| on: { | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| complete: { | |
| type: "final", | |
| data: { | |
| // TODO: remove type? | |
| config: (context) => context.config, | |
| workspace: (context) => context.workspace, | |
| }, | |
| }, | |
| }, | |
| }); | |
| //# sourceMappingURL=configMachine.js.map | |
| const x = Machine({ | |
| id: "config", | |
| initial: "initial", | |
| strict: true, | |
| context: { | |
| workspace: undefined, | |
| errorMessage: undefined, | |
| config: undefined, | |
| }, | |
| states: { | |
| initial: { | |
| invoke: { | |
| src: "getWorkspace", | |
| onDone: { | |
| target: "inWorkspace", | |
| actions: assign({ | |
| workspace: (_context, event) => event.data, | |
| }), | |
| }, | |
| onError: "noWorkspace", | |
| }, | |
| }, | |
| inWorkspace: { | |
| invoke: { | |
| src: "getConfig", | |
| onDone: { | |
| target: "complete", | |
| actions: assign({ | |
| config: (_context, event) => { | |
| return event.data; | |
| }, | |
| }), | |
| }, | |
| onError: [ | |
| { | |
| target: "configNotFound", | |
| cond: function configNotFound(_context, event) { | |
| return event.data && event.data.problem === "config_not_found"; | |
| }, | |
| actions: assign({ | |
| // TODO types | |
| errorMessage: (_context, event) => event.data.message, | |
| }), | |
| }, | |
| { | |
| target: "configInvalid", | |
| cond: function configInvalid(_context, event) { | |
| return event.data && event.data.problem === "config_invalid"; | |
| }, | |
| actions: assign({ | |
| errorMessage: (_context, event) => event.data.message, | |
| }), | |
| }, | |
| ], | |
| }, | |
| }, | |
| configNotFound: { | |
| invoke: { src: "renderConfigNotFound" }, | |
| on: { | |
| GENERATE: "generating", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| configInvalid: { | |
| invoke: { src: "renderConfigInvalid" }, | |
| on: { | |
| EDIT: "edit", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| edit: { | |
| entry: "EDIT_CONFIG", | |
| on: { | |
| "": "complete", | |
| }, | |
| }, | |
| generating: { | |
| invoke: { | |
| id: "generateConfig", | |
| src: "generateConfig", | |
| onDone: "complete", | |
| onError: "generationFailed", | |
| }, | |
| }, | |
| generationFailed: { | |
| invoke: { src: "renderGenerationFailed" }, | |
| on: { | |
| // RETRY: "generating", | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| noWorkspace: { | |
| invoke: { src: "renderNoWorkspace" }, | |
| on: { | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| noEditor: { | |
| invoke: { src: "renderNoEditor" }, | |
| on: { | |
| DISMISS: "complete", | |
| }, | |
| }, | |
| complete: { | |
| type: "final", | |
| data: { | |
| // TODO: remove type? | |
| config: (context) => context.config, | |
| workspace: (context) => context.workspace, | |
| }, | |
| }, | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment