Last active
May 28, 2021 22:49
-
-
Save peterfarrell/aa7e534e257201bd182588a88b88096f to your computer and use it in GitHub Desktop.
Revisions
-
peterfarrell revised this gist
May 28, 2021 . 1 changed file with 57 additions and 40 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 @@ -9,10 +9,64 @@ // - raise // - actions // - XState (all XState exports) const fetchMachine = Machine({ id: 'fetch', initial: 'idle', context: { item: undefined, retries: 0 }, states: { idle: { on: { FETCH: 'loading', }, after: { 1000: { target: 'loading' } } }, loading: { on: { RESOLVE: 'item', REJECT: 'failure' } }, item: { on: { FETCH: 'loading' } }, failure: { on: { RETRY: { target: 'loading', actions: assign({ retries: (context, event) => context.retries + 1 }) } } } } }); const orderMachine = Machine({ id: 'order', context: { item: undefined }, initial: 'loading', states: { loading: { invoke: { id: 'fetch', src: fetchMachine, onDone: { target: 'nuu', actions: assign({ item: (context, event) => event.data }) }, } }, nuu: { on: { MAKE_PENDING: 'pending', @@ -60,42 +114,5 @@ type: 'final' }, } }) -
peterfarrell revised this gist
May 28, 2021 . 1 changed file with 10 additions 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 @@ -22,25 +22,35 @@ on: { ACCEPT: 'accepted', CANCEL: 'canceled', HOLD: 'held', } }, accepted: { on: { UNPEND: 'pending', PROCESS: 'in_process', CANCEL: 'canceled', HOLD: 'held', } }, in_process: { on: { COMPLETE: 'completed', CANCEL: 'canceled', HOLD: 'held', } }, completed: { on: { DELIVER: 'delivered', PICKUP: 'delivered', CANCEL: 'canceled', HOLD: 'held', } }, held: { on: { UNHOLD: 'completed' } }, delivered: { -
peterfarrell revised this gist
May 28, 2021 . 1 changed file with 23 additions and 7 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 @@ -21,17 +21,33 @@ pending: { on: { ACCEPT: 'accepted', CANCEL: 'canceled', } }, accepted: { on: { PROCESS: 'in_process', CANCEL: 'canceled', } }, in_process: { on: { COMPLETE: 'completed', CANCEL: 'canceled', } }, completed: { on: { DELIVER: 'delivered', PICKUP: 'delivered', CANCEL: 'canceled', } }, delivered: { type: 'final' }, canceled: { type: 'final' }, } } -
peterfarrell created this gist
May 28, 2021 .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,75 @@ // Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const orderStates = { initial: 'nuu', states: { nuu: { on: { MAKE_PENDING: 'pending', }, }, pending: { on: { ACCEPT: 'accepted', } }, accepted: {}, in_process: {}, completed: {}, canceled: { type: 'final' }, hist: { type: 'history', history: 'shallow' // optional; default is 'shallow' }, } } const fetchMachine = Machine({ id: 'fetch', initial: 'idle', context: { retries: 0 }, states: { idle: { on: { FETCH: 'loading' } }, loading: { on: { RESOLVE: 'item', REJECT: 'failure' } }, item: { on: { FETCH: 'loading' }, ...orderStates, }, failure: { on: { RETRY: { target: 'loading', actions: assign({ retries: (context, event) => context.retries + 1 }) } } } } });