Created
January 3, 2020 22:14
-
-
Save jankei/2b292ecc5dc22ab51ac7988f500b188a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 prebillerVerifiedMachine = Machine( | |
{ | |
id: 'prebillerVerified', | |
initial: 'disabled', | |
context: { | |
warnings: [], | |
}, | |
states: { | |
disabled: { | |
id: 'disabled', | |
on: { | |
ENABLE: { | |
target: 'enabled', | |
cond: 'noWarnings', | |
}, | |
ADD_WARNING: { | |
actions: ['addWarning'], | |
}, | |
REMOVE_WARNING: { | |
actions: ['removeWarning'], | |
}, | |
}, | |
}, | |
enabled: { | |
initial: 'unchecked', | |
states: { | |
unchecked: { | |
on: { | |
CHECK: 'checked', | |
}, | |
}, | |
checked: { | |
on: { UNCHECK: 'unchecked' }, | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
addWarning: assign({ | |
warnings: (context, event) => context.warnings.splice(event.index, 0, event.message), | |
}), | |
removeWarning: assign({ | |
warnings: (context, event) => { | |
if (event.index && event.message) { | |
context.warnings.splice(event.index, 0, event.message).filter(Boolean); | |
} else return event.warnings; | |
}, | |
}), | |
}, | |
guards: { | |
noWarnings: context => context.warnings.length === 0, | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment