Last active
April 10, 2020 09:13
-
-
Save FrankMerema/e9d254736649f2320602da2c2da822c1 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 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