Skip to content

Instantly share code, notes, and snippets.

@pixelart7
Last active August 31, 2020 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelart7/3033c18917274d0f8bdb344965afb481 to your computer and use it in GitHub Desktop.
Save pixelart7/3033c18917274d0f8bdb344965afb481 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const expenseMachine = Machine({
id: 'expense',
initial: 'pending_approve',
context: {
paymentMethod: 'CASH',
},
states: {
pending_approve: {
on: {
APPROVE: 'ready_to_pay',
REJECT: 'cancelled',
}
},
ready_to_pay: {
on: {
PAY: [
{
target: 'awaiting_customer_process',
cond: 'isCheque',
},
{
target: 'completed',
cond: 'isCash'
}
],
CANCEL: 'cancelled',
}
},
awaiting_customer_process: {
on: {
CUSTOMER_RECEIVE_MONEY: 'completed',
}
},
completed: {
type: 'final'
},
cancelled: {
type: 'final'
}
}
}, {
guards: {
isCash: (context) => (context.paymentMethod === 'CASH') ? true : false,
isCheque: (context) => (context.paymentMethod === 'CHEQUE') ? true : false,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment