Skip to content

Instantly share code, notes, and snippets.

@schpet
Last active December 3, 2019 17:15
Show Gist options
  • Select an option

  • Save schpet/7b560bf41d1ecf7531f778e0117ca2f1 to your computer and use it in GitHub Desktop.

Select an option

Save schpet/7b560bf41d1ecf7531f778e0117ca2f1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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