Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
Last active September 23, 2019 14:46
Show Gist options
  • Save tgvashworth/11fd472ffe90a39e1609e41d4abc8424 to your computer and use it in GitHub Desktop.
Save tgvashworth/11fd472ffe90a39e1609e41d4abc8424 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 applicationStates = {
id: 'applied',
initial: 'waiting',
states: {
waiting: {
on: {
BG_AUDIT: [
{ target: 'auditing', cond: 'isSelectedForAudit' },
{ target: 'done' }
]
}
},
auditing: {
on: {
BG_AUDIT_PASS: {
target: 'done',
actions: 'assignAuditPass'
},
BG_AUDIT_SKIP: {
target: 'done',
actions: 'assignAuditSkip'
},
BG_AUDIT_FAIL: {
target: 'done',
actions: 'assignAuditFail'
}
}
},
done: {
type: 'final'
}
}
}
const memberMachine = Machine({
id: 'member',
initial: 'none',
context: {
group: 'none',
audit: 'none',
selected: true
},
states: {
none: {
on: {
BG_APPLICATION: { target: 'applied', actions: 'assignBG' },
CG_INSTRUCTION: { target: 'eligible', actions: 'assignCG' }
}
},
applied: {
on: {
CG_INSTRUCTION: { target: 'eligible', actions: 'assignCG' },
LOSS: { target: 'ineligible', cond: 'isBG' }
},
...applicationStates,
onDone: [
{ target: 'eligible', cond: 'isAuditPassed' },
{ target: 'ineligible' }
]
},
eligible: {
on: {
LOSS: { target: 'ineligible', cond: 'isBG' }
}
},
ineligible: {
on: {
CG_INSTRUCTION: { target: 'eligible', actions: 'assignCG' }
}
}
}
}, {
actions: {
assignBG: assign({
group: 'bg'
}),
assignCG: assign({
group: 'cg'
}),
assignAuditPass: assign({
audit: 'pass'
}),
assignAuditFail: assign({
audit: 'fail'
}),
assignAuditSkip: assign({
audit: 'skip'
}),
},
guards: {
isBG: (context) => context.group === 'bg',
isSelectedForAudit: ({ selected }) => selected,
isAuditPassed: ({ audit, selected }) => audit === 'pass' || audit === 'skip' || !selected
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment