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: {
students: [],
grades: [],
services: [],
},
states: {
editing: {
on: {
SELECT_MODALITY: `loading`,
SUBMIT: `creating`,
SEARCH_STUDENT: {
cond: `searchValid`,
target: `searching`,
},
},
},
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`,
},
},
},
},
},
searching: {
invoke: {
id: `searchStudents`,
src: `searchStudents`,
onDone: {
actions: `setStudents`,
target: `editing`,
},
},
},
creating: {
invoke: {
id: `createContract`,
src: `createContract`,
onDone: `success`,
onError: {
actions: `handleGraphQLErrors`,
target: `editing`,
},
},
},
success: {
entry: `createContractSuccess`,
type: `final`,
},
},
},
{
actions: {
setStudents: assign((ctx, event) => {
// ctx.students = event.data
}),
setGrades: assign((ctx, event) => {
// ctx.grades = event.data.allGrades
}),
setServices: assign((ctx, event) => {
// ctx.services = event.data.allServices
}),
},
guards: {
hasErrors: (ctx, event) => false,
searchValid: (ctx, event) => true,
},
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment