Skip to content

Instantly share code, notes, and snippets.

@abinavseelan
Created February 9, 2020 03:27
Show Gist options
  • Save abinavseelan/282fdcdc73881a0b71e22ffd317fa20a to your computer and use it in GitHub Desktop.
Save abinavseelan/282fdcdc73881a0b71e22ffd317fa20a 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 SANITY_CHECKS = {
id: 'sanityChecks',
initial: 'CHECK_IF_HEARTBEAT',
states: {
CHECK_IF_HEARTBEAT: {
on: {
'NO_HOOK_ID': '#githubHook.RETURN_204',
'HOOK_ID_PRESENT': 'VERIFY_ACTION_TYPE',
}
},
VERIFY_ACTION_TYPE: {
on: {
'ACTION_TYPE:OPEN': 'CHECK_PULL_ID',
'ACTION_TYPE:SYNC': 'CHECK_PULL_ID',
'ALL_OTHER_ACTIONS': '#githubHook.RETURN_204',
}
},
CHECK_PULL_ID: {
on: {
PRESENT: '#githubHook.RETURN_204',
'NOT_PRESENT': '#githubHook.RETURN_400'
}
}
}
}
const fetchMachine = Machine({
id: 'githubHook',
initial: 'IDLE',
states: {
IDLE: {
type: 'final'
},
HOOK_TRIGGERED: {
on: {
'VERIFY_HOOK_DETAILS': 'SANITY_CHECKS',
}
},
SANITY_CHECKS: {
...SANITY_CHECKS
},
'RETURN_204': {
type: 'final'
},
'RETURN_400': {
type: 'final'
}
},
on: {
GITHUB_PULL_REQUEST_RAISED: 'HOOK_TRIGGERED',
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment