Created
April 21, 2020 19:05
-
-
Save adamterlson/2a8317e74c305718847b4ce98c05c8bb 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
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, | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment