Skip to content

Instantly share code, notes, and snippets.

@hosmelq
Last active April 18, 2020 00:40
Show Gist options
  • Save hosmelq/e94329abf9741d1101334a73cd41787c to your computer and use it in GitHub Desktop.
Save hosmelq/e94329abf9741d1101334a73cd41787c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const CourierOnboardingVerificationsItemState = {
IN_REVISION: `IN_REVISION`,
PENDING: `PENDING`,
VERIFIED: `VERIFIED`,
}
const CourierState = {
ACTIVE: `ACTIVE`,
BLOCKED: `BLOCKED`,
PENDING: `PENDING`,
REJECTED: `REJECTED`,
}
const checkMachine = Machine(
{
id: `check`,
initial: `unknown`,
states: {
unknown: {
on: {
'': [
{
target: `completed`,
cond: (ctx) => ctx.completed,
},
{
target: `pending`,
},
],
},
},
inRevision: {},
pending: {},
verified: {},
},
},
{
guards: {
isInRevision: (ctx) => {
return ctx.state === CourierOnboardingVerificationsItemState.IN_REVISION
},
isPending: (ctx) => {
return ctx.state === CourierOnboardingVerificationsItemState.PENDING
},
isVerified: (ctx) => {
return ctx.state === CourierOnboardingVerificationsItemState.VERIFIED
},
},
}
)
Machine(
{
id: `onboard`,
initial: `initializing`,
context: {
checks: [],
state: null,
},
states: {
initializing: {
entry: `initializeChecks`,
on: {
'': `unknown`,
},
},
initializeChecks: {},
unknown: {
on: {
'': [
{
cond: `isActive`,
target: `active`,
},
],
},
},
active: {
meta: {
title: `Activa`,
},
},
},
},
{
actions: {
initializeChecks: assign({
checks: (ctx) => {
return ctx.checks.map(check => ({
...check,
ref: spawn(checkMachine.withContext(check)),
}));
}
})
},
guards: {
isActive: (ctx) => ctx.state === CourierState.ACTIVE,
},
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment