Skip to content

Instantly share code, notes, and snippets.

@hosmelq
Last active April 25, 2020 03:55
Show Gist options
  • Save hosmelq/38b8d30b2d5b040e4090b07899d2b4be to your computer and use it in GitHub Desktop.
Save hosmelq/38b8d30b2d5b040e4090b07899d2b4be to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine(
{
id: `createContract`,
initial: `editing`,
context: {
grades: [],
services: [],
},
states: {
editing: {
on: {
SELECT_MODALITY: `loading`,
SUBMIT: `creating`,
},
},
loading: {
onDone: `editing`,
type: `parallel`,
states: {
grades: {
initial: `loading`,
states: {
loading: {
invoke: {
id: `loadGrades`,
src: `loadGrades`,
onDone: {
actions: `setGrades`,
target: `done`,
},
},
},
done: {
type: `final`,
},
},
},
services: {
initial: `loading`,
states: {
loading: {
invoke: {
id: `loadServices`,
src: `loadServices`,
onDone: {
actions: `setServices`,
target: `done`,
},
},
},
done: {
type: `final`,
},
},
},
},
},
creating: {
invoke: {
id: `createContract`,
src: `createContract`,
onDone: `success`,
onError: {
actions: `handleGraphQLErrors`,
target: `editing`,
},
},
},
success: {
entry: `createContractSuccess`,
type: `final`,
},
},
},
{
actions: {
setGrades: assign((ctx, event) => {
// ctx.grades = event.data.allGrades
}),
setServices: assign((ctx, event) => {
// ctx.services = event.data.allServices
}),
},
guards: {
hasErrors: (ctx, event) => !!event.data?.errors,
},
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment