Created
May 14, 2020 18:22
-
-
Save christiannwamba/8a2a28c5113c2ce469c4a4307f421168 to your computer and use it in GitHub Desktop.
Revisions
-
christiannwamba created this gist
May 14, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ // 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, }, } );