Created
July 4, 2021 19:22
-
-
Save farskid/78d891ac57e2ff7d4419d0dec8fb88bb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 editorPanelMachine = Machine({ | |
context: {immediateUpdate: true}, | |
initial: 'booting', | |
states: { | |
booting: {}, | |
active: {}, | |
updating: { | |
entry: send('UPDATE_MACHINE_PRESSED'), | |
always: 'active', | |
}, | |
compiling: { | |
invoke: { | |
src: (ctx) => { | |
const uri = ctx.editorRef.Uri.parse(ctx.mainFile); | |
const compiledJSPromise = ctx | |
.editorRef.languages.typescript.getTypeScriptWorker() | |
.then((worker) => worker(uri)) | |
.then((client) => client.getEmitOutput(uri.toString())) | |
.then((result) => result.outputFiles[0].text); | |
return compiledJSPromise.then((js) => { | |
const machines = parseMachines(removeExportsImports(js)); | |
return machines; | |
}); | |
}, | |
onDone: { | |
target: 'updating', | |
actions: [ | |
assign({ | |
machines: (_, e) => e.data, | |
}), | |
], | |
}, | |
onError: { | |
target: 'active', | |
actions: [ | |
(_, e) => console.error(e.data), | |
send((_, e) => ({ | |
type: 'EDITOR_ENCOUNTERED_ERROR', | |
message: e.data.message, | |
})), | |
], | |
}, | |
}, | |
}, | |
}, | |
on: { | |
EDITOR_READY: [ | |
{ | |
cond: (ctx) => ctx.immediateUpdate, | |
actions: [ | |
assign({ editorRef: (_, e) => e.editorRef }), | |
], | |
target: 'compiling', | |
}, | |
{ | |
target: 'active', | |
actions: assign({ editorRef: (_, e) => e.editorRef }), | |
}, | |
], | |
EDITOR_CHANGED_VALUE: { | |
actions: [assign({ code: (_, e) => e.code })], | |
}, | |
EDITOR_ENCOUNTERED_ERROR: { | |
actions: (_, e) => console.error(e.data) | |
}, | |
UPDATE_MACHINE_PRESSED: { | |
actions: 'onChange', | |
}, | |
COMPILE: 'compiling', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment