Skip to content

Instantly share code, notes, and snippets.

@cunneen
Last active July 12, 2023 15:34
Show Gist options
  • Save cunneen/7ec38b80014d2200422c2c4964ad8e2a to your computer and use it in GitHub Desktop.
Save cunneen/7ec38b80014d2200422c2c4964ad8e2a 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 addStudentMachine = Machine({
id: 'addStudent',
initial: 'initial',
context: {
retries: 0
},
states: {
initial: {
on: {
USI_ENTERED: 'findUSIMatch',
DOB_ENTERED: 'findFuzzyMatch'
}
},
findUSIMatch: {
on: {
USI_MATCH_FOUND: 'confirmAddExistingStudent',
USI_MATCH_NOT_FOUND: 'notifyUSIMatchNotFound'
}
},
notifyUSIMatchNotFound: {
on: {
OK: 'initial'
}
},
findFuzzyMatch: {
on: {
FUZZY_MATCH_FOUND: 'presentFuzzyMatch',
FUZZY_MATCH_NOT_FOUND: 'notifyNoFuzzyMatchFound'
}
},
presentFuzzyMatch: {
on: {
REJECT_SUGGESTIONS: 'addNewOrTryAgain',
SELECT_STUDENT:
'confirmAddExistingStudent'
}
},
addNewOrTryAgain: {
on: {
ADD_NEW: 'newStudent',
TRY_AGAIN: 'initial'
}
},
notifyNoFuzzyMatchFound: {
on: {
OK: 'addNewOrTryAgain'
}
},
confirmAddExistingStudent: {
type: 'final'
},
newStudent: {
type: 'final'
},
failure: {
type: 'final'
},
dismissed: {
type: 'final'
}
},
on: {
CANCEL: 'initial',
CLOSE: 'dismissed',
ERROR: 'failure'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment