Skip to content

Instantly share code, notes, and snippets.

@dubbs
Last active August 15, 2021 21:40
Show Gist options
  • Save dubbs/5204d5b8b8a667ae3c38792586828c5b to your computer and use it in GitHub Desktop.
Save dubbs/5204d5b8b8a667ae3c38792586828c5b 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 questionMachine = Machine({
id: 'question',
initial: 'query',
context: {},
states: {
query: {
invoke: {
src: 'query',
onDone: 'done',
onError: 'error'
}
},
done: {
type: 'final'
},
error: {
on: {
RETRY: 'query'
}
}
}
}, {
services: {
query: () => {
return Promise.resolve('question')
}
}
});
const helpMachine = Machine({
id: 'help',
initial: 'closed',
context: {
questions: []
},
states: {
closed: {
on: {
TOGGLE: 'open'
}
},
open: {
on: {
TOGGLE: 'closed',
REQUEST: {
actions: assign({
questions: (ctx, event) => [
...ctx.questions,
{
question: event.question,
ref: spawn(questionMachine, {
id: `question-${event.id}`,
sync: true
})
}
]
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment