Last active
March 26, 2021 17:12
-
-
Save MaelFr/c650c9dd130201e3e82d63239d1eb85f to your computer and use it in GitHub Desktop.
Revisions
-
MaelFr revised this gist
Mar 26, 2021 . No changes.There are no files selected for viewing
-
MaelFr revised this gist
Nov 6, 2020 . 1 changed file with 3 additions and 1 deletion.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 @@ -62,7 +62,9 @@ type: 'final' }, failure: { on: { RETRY: 'loading' } } } }); -
MaelFr revised this gist
Nov 6, 2020 . 1 changed file with 1 addition and 0 deletions.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 @@ -55,6 +55,7 @@ longLoading: { on: { RESOLVE: 'success', REJECT: 'failure', } }, success: { -
MaelFr created this gist
Nov 6, 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,68 @@ // Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const fetchMachine = Machine({ id: 'fetch', initial: 'idle', context: { elapsed: 0, duration: 2, interval: 0.1 }, states: { idle: { on: { FETCH: 'loading' } }, loading: { invoke: { src: context => cb => { const interval = setInterval(() => { cb('TICK'); }, 1000 * context.interval); return () => { clearInterval(interval); }; } }, on: { '': { target: 'longLoading', cond: context => { return context.elapsed >= context.duration; } }, RESOLVE: 'success', REJECT: 'failure', TICK: { actions: assign({ elapsed: context => +(context.elapsed + context.interval).toFixed(2) }) } } }, longLoading: { on: { RESOLVE: 'success', } }, success: { type: 'final' }, failure: { type: 'final' } } });