Last active
September 23, 2020 08:42
-
-
Save dougdroper/ada69f43200838ee2ebd222fd63308e1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contactAndDelivery = { | |
id: 'contactAndDelivery', | |
initial: 'name', | |
states: { | |
name: { | |
on: { | |
SUCCESS: 'address' | |
} | |
}, | |
address: { | |
on: { | |
SUCCESS: 'end' | |
} | |
}, | |
end: { | |
type: 'final' | |
} | |
} | |
} | |
const yourKit = { | |
id: 'yourKit', | |
initial: 'kit_type', | |
states: { | |
kit_type: { | |
on: { | |
valid: 'gender' | |
} | |
}, | |
gender: { | |
on: { | |
SUCCESS: '#contactAndDelivery' | |
} | |
} | |
} | |
}; | |
const ageAndPostcode = { | |
id: 'step1', | |
initial: 'dob', | |
states: { | |
dob: { | |
on: { | |
SUCCESS: 'postcode', | |
UNDER_AGE: '#failure.underage', | |
OVERAGE_AGE: '#failure.overage' | |
} | |
}, | |
postcode: { | |
on: { | |
SUBMIT: { | |
target: 'check_region', | |
cond: ctx => ctx.postcode.length === 0 | |
} | |
} | |
}, | |
check_region: { | |
on: { | |
VALID_REGION: 'signs' | |
} | |
}, | |
signs: { | |
on: { | |
SUCCESS: 'consent', | |
} | |
}, | |
consent: { | |
on: { | |
SUCCESS: '#yourKit' | |
} | |
} | |
} | |
} | |
const fetchMachine = Machine({ | |
id: "sh24", | |
context: { | |
retries: 0, | |
postcode: '' | |
}, | |
initial: 'step1', | |
states: { | |
step1: { | |
...ageAndPostcode | |
}, | |
step2: { | |
...yourKit | |
}, | |
step3: { | |
...contactAndDelivery | |
}, | |
failure: { | |
id: 'failure', | |
initial: 'underage', | |
states: { | |
underage: { | |
meta: { | |
message: "underage" | |
} | |
}, | |
overage: { | |
meta: { | |
message: "overage" | |
} | |
}, | |
outside: { | |
meta: { | |
message: "outside" | |
} | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment