Skip to content

Instantly share code, notes, and snippets.

@parties
Last active October 4, 2021 23:40
Show Gist options
  • Save parties/1229c93d90c159006d206e2f75da02ad to your computer and use it in GitHub Desktop.
Save parties/1229c93d90c159006d206e2f75da02ad to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const dataEditorMachine = Machine({
id: 'data_editor',
initial: 'idle',
context: {
retries: 0,
generationSource: '',
},
states: {
idle: {
id: 'idle',
on: {
CHOOSE_FUNCTION: {
target: 'validate',
actions: assign({
generationSource: 'function',
})
},
CHOOSE_KIND: {
target: 'validate',
actions: assign({
generationSource: 'kind',
})
},
CHOOSE_DEFAULT: {
target: 'validate',
actions: assign({
generationSource: 'default',
})
},
}
},
validate: {
id: 'validate',
initial: 'idle',
states: {
// a state for waiting for the user
// to choose where to go next
idle: {
on: {
SKIP_WARNING: {
target: '#generate'
}
}
},
levels: {
on: {
SUCCESS: 'evidence',
FAILURE: {
target: '#idle',
actions: assign({
error: 'Too many levels'
})
},
}
},
evidence: {
on: {
SUCCESS: 'connectedness',
FAILURE: {
target: 'idle'
}
}
},
connectedness: {},
}
},
generate: {
id: 'generate',
on: {
ERROR: 'generate',
SUCCESS: 'modify'
}
},
modify: {},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment