Last active
August 15, 2021 21:40
-
-
Save dubbs/5204d5b8b8a667ae3c38792586828c5b 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
// 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