Skip to content

Instantly share code, notes, and snippets.

@rafaelmotta
Created May 20, 2022 09:01
Show Gist options
  • Save rafaelmotta/ef45cb3025b08b930f2d12349abce0e5 to your computer and use it in GitHub Desktop.
Save rafaelmotta/ef45cb3025b08b930f2d12349abce0e5 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 fetchMachine = Machine({
id: 'bifrostMachine',
initial: 'emailIdentification',
context: {
identification: {},
registration: {},
},
states: {
emailIdentification: {
on: {
USER_FOUND: {
target: 'phoneVerification',
actions: assign((context, { phoneLastTwoDigits }) => {
context.identification.phoneLastTwoDigits = phoneLastTwoDigits;
return context;
}),
},
USER_NOT_FOUND: {
target: 'phoneRegistration',
actions: assign((context, { email }) => {
context.registration.email = email;
return context;
}),
},
},
},
phoneRegistration: {
on: {
CHANGE_EMAIL: {
target: 'emailIdentification',
actions: assign(context => {
context.identification = {};
context.registration = {};
return context;
}),
},
PHONE_SUBMITTED: {
target: 'emailIdentification',
},
},
},
phoneVerification: {
on: {
USER_CREATED: {
target: 'registration',
},
USER_INHERITED: {
target: 'verificationSuccess',
},
},
},
registration: {
type: 'compound',
initial: 'basicInformation',
states: {
basicInformation: {
on: {
BASIC_INFORMATION_SUBMITTED: {
target: 'residentialAddress',
actions: assign((context, { basicInformation }) => {
context.registration = {
...context.registration,
...basicInformation,
};
return context;
}),
},
},
},
residentialAddress: {
on: {
RESIDENTIAL_ADDRESS_SUBMITTED: {
target: 'ssn',
actions: assign((context, { residentialAddress }) => {
context.registration = {
...context.registration,
...residentialAddress,
};
return context;
}),
},
},
},
ssn: {
on: {
SSN_SUBMITTED: {
target: 'registrationSuccess',
actions: assign((context, { ssn }) => {
context.registration.ssn = ssn;
return context;
}),
},
},
},
registrationSuccess: {
type: 'final',
},
},
},
verificationSuccess: {
type: 'final',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment