Last active
August 31, 2020 03:50
-
-
Save pixelart7/3033c18917274d0f8bdb344965afb481 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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 characters
// 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