Skip to content

Instantly share code, notes, and snippets.

@FrankMerema
Last active April 10, 2020 09:13
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 FrankMerema/e9d254736649f2320602da2c2da822c1 to your computer and use it in GitHub Desktop.
Save FrankMerema/e9d254736649f2320602da2c2da822c1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const canActivateNextComponent = (ctx, event, { state }) => true; // check if next component can be activated
const canActivatePreviousComponent = (ctx, event, { state }) => true; // check if previous component can be activated
const navigationMachine = Machine(
{
id: 'navigationMachine',
initial: 'overview',
context: {
addressValid: true,
fulfilmentValid: false,
slotsValid: false,
overviewValid: false,
thankyouValid: false,
},
states: {
address: {
on: {
NEXT: {
target: 'fulfilment',
cond: canActivateNextComponent,
},
PREVIOUS: undefined,
},
},
fulfilment: {
on: {
NEXT: {
target: 'slots',
cond: canActivateNextComponent,
},
PREVIOUS: {
target: 'address',
cond: canActivatePreviousComponent,
},
},
},
slots: {
on: {
NEXT: {
target: 'overview',
cond: canActivateNextComponent,
},
PREVIOUS: [{
target: 'fulfilment',
cond: canActivatePreviousComponent,
}, {
target: 'address'
}],
},
},
overview: {
on: {
NEXT: {
target: 'thankyou',
cond: canActivateNextComponent,
},
PREVIOUS: [{
target: 'slots',
cond: canActivatePreviousComponent,
}, {
target: 'fulfilment',
cond: canActivatePreviousComponent,
}, {
target: 'address'
}],
},
},
thankyou: {
type: 'final',
},
},
},
{
guards: {
canActivateNextComponent,
canActivatePreviousComponent,
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment