Created
April 21, 2020 19:05
-
-
Save adamterlson/2a8317e74c305718847b4ce98c05c8bb to your computer and use it in GitHub Desktop.
Revisions
-
adamterlson created this gist
Apr 21, 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,78 @@ const transactionMachine = Machine({ id: 'transaction', initial: 'draft', states: { draft: { on: { AUTHORIZE_PAYMENT: { target: 'authorizing', }, ADD_ITEM: { target: 'draft', }, ADD_CUSTOMER: { target: 'draft', }, TRANSFER: 'transferred', }, }, authorizing: { on: { AUTHORIZED: 'finalizing' } }, finalizing: { on: { COMPLETE: 'completed', } }, error: { on: { RETRY: { target: 'draft', }, TRANSFER: 'transferred', }, }, transferred: { type: 'final', }, completed: { type: 'final', }, }, }) const activityStates = { id: 'activity', initial: 'idle', states: { idle: { on: { CREATE_TRANSACTION: 'transaction' } }, transaction: { invoke: { src: transactionMachine, onDone: 'idle', onError: 'idle', } } } } const socketMachine = Machine({ id: 'socket', initial: 'disconnected', states: { disconnected: { on: { CONNECT: 'connected' } }, connected: { ...activityStates, } } });