Appearance
Transaction Resolver
The transaction resolver exports a machine that is intended to be used as the child of another machine. This is done by invoking the machine and then transitioning to the relevant states based on it's emitted events.
Usage
js
import { createMachine } from 'xstate';
import { transactionsMachine } from '@fingermarkglobal/transactions.resolver';
const parentMachine = createMachine({
id: 'parent-machine',
initial: 'transactions',
context: {
settings: {
//...
},
},
states: {
transactions: {
invoke: {
id: 'transactions-machine',
src: transactionsMachine,
data: {
settings: context => context?.settings,
},
},
on: {
TRANSACTIONS_MACHINE_FAILURE: {
target: 'failure',
},
TRANSACTIONS_MACHINE_SUCCESS: {
target: 'success',
},
},
},
success: {
//...
},
failure: {
//...
},
},
});Context
Note this machine makes use of the data attribute which allows us to invoke child machines with exiting context.