Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Available variables:
- // - Machine
- // - interpret
- // - assign
- // - send
- // - sendParent
- // - spawn
- // - raise
- // - actions
- // - XState (all XState exports)
- const dismissReasonMachine = Machine({
- id: 'dismissReasonMachine',
- initial: 'load',
- context: {
- actions: [],
- reason: undefined,
- action: undefined,
- },
- states: {
- load: {
- invoke: {
- id: 'onLoad',
- src: 'onLoad',
- onDone: [
- {
- cond: 'hasActions',
- target: 'input',
- actions: ['setActions'],
- },
- {
- target: 'error.emptyActions'
- }
- ],
- onError: 'error.serverError',
- },
- on: {
- CANCEL: 'close',
- },
- },
- input: {
- on: {
- SELECT_ACTION: {
- actions: ['setAction'],
- },
- ENTER_REASON: {
- actions: ['setReason']
- },
- CANCEL: 'close',
- SUBMIT: 'save',
- }
- },
- save: {
- invoke: {
- id: 'onSave',
- src: 'onSave',
- onDone: 'success',
- onError: 'error.saveFailed'
- },
- },
- success: {
- on: {
- TIMER: 'close',
- },
- },
- error: {
- states: {
- emptyActions: {},
- serverError: {},
- saveFailed: {},
- }
- },
- close: {
- type: 'final',
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement