Skip to content

Instantly share code, notes, and snippets.

@pyoner
Last active October 16, 2021 12:34
Show Gist options
  • Save pyoner/078f590874d8200e8052f4864d9154fa to your computer and use it in GitHub Desktop.
Save pyoner/078f590874d8200e8052f4864d9154fa to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Project: Gtab
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const every = (...fn_names) => {
const name = fn_names.join(', ')
return {
type: name,
guards: fn_names
}
}
const asyncState = (src, onDone, onError = 'err') => {
const err = onError === 'err' ? {
on: {
RETRY: 'await'
}
} : null;
const state = {
initial: 'await',
states: {
await: {
invoke: {
src,
onDone,
onError
}
}
}
}
if (err) {
state.states.err = err
}
return state;
}
const gitMachine = Machine({
id: 'git',
initial: '$',
context: {
},
states: {
$: {
on: {
CLONE: 'clone'
}
},
clone: asyncState('gitClone', '#git.repo'),
repo: {
initial: '$',
states: {
$: {on: {
PULL: 'pull',
PUSH: 'push',
COMMIT: 'commit',
CHECKOUT: 'checkout',
MERGE: 'merge',
STATUS: 'status',
}},
pull: asyncState('gitPull', '#git.repo'),
push: asyncState('gitPush', '#git.repo'),
commit: asyncState('gitCommit', '#git.repo'),
checkout: asyncState('gitCheckout', '#git.repo'),
merge: asyncState('gitMerge', '#git.repo'),
status: asyncState('gitStatus', '#git.repo'),
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment