Last active
April 8, 2021 07:40
-
-
Save JReinhold/95ec8fcbf9a055b4053b13f41ed4bef9 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const documentIsProcessed = (context) => { | |
return context.documentIsProcessed; | |
}; | |
const uploadStates = { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
INIT_UPLOAD: 'uploading' | |
} | |
}, | |
uploading: { | |
on: { | |
UPLOAD_RESOLVED: 'processing', | |
UPLOAD_REJECTED: 'idle' // and an error notification | |
} | |
}, | |
processing: { | |
on: { | |
DOCUMENT_PROCESSING_RESOLVED: 'documentProcessed', | |
DOCUMENT_PROCESSING_REJECTED: 'documentProcessingFailed' | |
} | |
}, | |
documentProcessed: { | |
on: { | |
INITIATE_PAYMENT: 'showPayment' | |
} | |
}, | |
documentProcessingFailed: { | |
type: 'final' | |
}, | |
showPayment: { | |
on: { | |
PROCESS_PAYMENT: 'processingPayment', | |
CANCEL: 'documentProcessed' | |
} | |
}, | |
processingPayment: { | |
on: { | |
PAYMENT_RESOLVED: 'paymentDone', | |
PAYMENT_REJECTED: 'showPayment' // and an error notification | |
} | |
}, | |
paymentDone: { | |
type: 'final' | |
} | |
} | |
}; | |
const paymentStates = { | |
initial: 'noDocument', | |
states: { | |
noDocument: { | |
on: { | |
UPLOAD_RESOLVED: 'paymentReady' | |
} | |
}, | |
paymentReady: {} | |
} | |
}; | |
const documentMachine = Machine({ | |
id: 'document', | |
initial: 'upload', | |
context: { | |
documentProcessed: false | |
}, | |
states: { | |
upload: uploadStates, | |
}, | |
}, | |
{ | |
guards: { | |
documentIsProcessed | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment