Created
May 14, 2020 18:22
-
-
Save christiannwamba/8a2a28c5113c2ce469c4a4307f421168 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
// DEMO: Null or Transient Transitions with '' | |
// Cick TRY 3 times and it will get to success but will keep coming back to idle at 1 and 2 time | |
// You can see the state increment in the STATE tab when you click TRY | |
const ifAtFirstYouDontSucceed = Machine( | |
{ | |
id: 'tryTryAgain', | |
initial: 'idle', | |
context: { | |
tries: 0, | |
}, | |
states: { | |
idle: { | |
on: { TRY: 'trying' }, | |
}, | |
trying: { | |
entry: ['incTries'], | |
on: { | |
'': [{ target: 'success', cond: 'triedEnough' }, { target: 'idle' }], | |
}, | |
}, | |
success: {}, | |
}, | |
}, | |
{ | |
actions: { | |
incTries: assign({ | |
tries: (ctx) => ctx.tries + 1, | |
}), | |
}, | |
guards: { | |
triedEnough: (ctx) => ctx.tries > 2, | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment