Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
Last active September 16, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgvashworth/8a0528cc0e77cdba63f1674a22a6c3c0 to your computer and use it in GitHub Desktop.
Save tgvashworth/8a0528cc0e77cdba63f1674a22a6c3c0 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: 'applied',
states: {
applied: {},
auditing: {},
done: {
type: 'final'
}
}
}
const memberMachine = Machine({
id: 'member',
initial: 'none',
context: {
group: 'none'
},
states: {
none: {
on: {
BG_APPLICATION: { target: 'applied', actions: 'assignBG' },
CG_INSTRUCTION: { target: 'eligible', actions: 'assignCG' }
}
},
applied: {
on: {
CG_INSTRUCTION: { target: 'eligible', actions: 'assignCG' }
},
...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'
})
},
guards: {
isBG: (context) => context.group === 'bg'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment