Created
August 8, 2019 15:49
-
-
Save flybayer/11dad7fdc14fddc8f5f374d0abac7d78 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 fetchMachine = Machine({ | |
id: "checkoutApp", | |
initial: "studentEntry", | |
strict: true, | |
context: {}, | |
states: { | |
studentEntry: { | |
type: "atomic", | |
on: { | |
CHANGE_STUDENTS: { | |
actions: assign((context, event) => { | |
const students = event.value | |
return { | |
students, | |
someoneTakingLanguage: students.some(student => student.tests.language), | |
someoneTakingScience: students.some(student => student.tests.science), | |
} | |
}), | |
}, | |
NEXT: [{ target: "scheduling.review", cond: "bookingComplete" }, { target: "scheduling" }], | |
}, | |
}, | |
scheduling: { | |
type: "compound", | |
on: { | |
CHANGE_BOOKINGS: { | |
actions: assign({ | |
bookings: (context, event) => ({ ...context.bookings, ...event.bookings }), | |
}), | |
}, | |
NEXT: "checkout", | |
"SCHEDULE.READING": "scheduling.reading", | |
"SCHEDULE.MATH": "scheduling.math", | |
"SCHEDULE.LANGUAGE": "scheduling.language", | |
"SCHEDULE.SCIENCE": "scheduling.science", | |
"NAVIGATE.STUDENT_ENTRY": "studentEntry", | |
}, | |
initial: "reading", | |
states: { | |
reading: { | |
entry: send({ | |
type: "CHANGE_BOOKINGS", | |
bookings: { math: undefined, language: undefined, science: undefined }, | |
}), | |
on: { | |
NEXT: [{ target: "review", cond: "bookingComplete" }, { target: "math" }], | |
}, | |
}, | |
math: { | |
entry: send({ | |
type: "CHANGE_BOOKINGS", | |
bookings: { language: undefined, science: undefined }, | |
}), | |
on: { | |
NEXT: [ | |
{ target: "review", cond: "bookingComplete" }, | |
{ | |
target: "language", | |
cond: { | |
type: "needTest", | |
testName: "language", | |
}, | |
}, | |
], | |
}, | |
}, | |
language: { | |
entry: send({ | |
type: "CHANGE_BOOKINGS", | |
bookings: { science: undefined }, | |
}), | |
on: { | |
NEXT: [ | |
{ target: "review", cond: "bookingComplete" }, | |
{ | |
target: "science", | |
cond: { | |
type: "needTest", | |
testName: "science", | |
}, | |
}, | |
], | |
}, | |
}, | |
science: { | |
on: { | |
NEXT: "review", | |
}, | |
}, | |
review: {}, | |
}, | |
}, | |
checkout: { | |
type: "atomic", | |
on: { | |
"NAVIGATE.STUDENT_ENTRY": "studentEntry", | |
"NAVIGATE.SCHEDULING": "scheduling.review", | |
SUCCESS: "checkoutSuccess", | |
}, | |
}, | |
checkoutSuccess: { | |
type: "final", | |
}, | |
}, | |
}, | |
{ | |
actions: {}, | |
guards: { | |
needTest: (context, event, { cond }) => { | |
// logic omitted | |
return true | |
}, | |
bookingComplete: (context, event) => { | |
// logic ommitted | |
return false | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment