Skip to content

Instantly share code, notes, and snippets.

@JReinhold
Last active April 8, 2021 07:40
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 JReinhold/95ec8fcbf9a055b4053b13f41ed4bef9 to your computer and use it in GitHub Desktop.
Save JReinhold/95ec8fcbf9a055b4053b13f41ed4bef9 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 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