Last active
October 19, 2020 11:46
-
-
Save Waxolunist/d12d1d510ee29b08b50241dc12e54ada 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 review = Machine({ | |
id: 'review', | |
initial: 'idle', | |
context: { | |
manual: true, | |
// --- | |
audit: true, | |
riskcategory: 'low', | |
error: true, | |
controlReason: '', | |
errorReason: '', | |
// --- | |
}, | |
states: { | |
idle: { | |
on: { | |
REVIEW: 'startReview' | |
} | |
}, | |
startReview: { | |
invoke: { | |
src: 'startService', | |
onDone: 'open', | |
onError: 'failure' | |
} | |
}, | |
open: { | |
on: { | |
STARTPROGRESS: 'inProgress', | |
OVERDUE: 'overdue' | |
} | |
}, | |
inProgress: { | |
on: { | |
FINISHDATAINPUT: 'dataReceived' | |
} | |
}, | |
dataReceived: { | |
invoke: { | |
src: 'riskEvaluation', | |
onDone: 'sample', | |
onError: 'failure' | |
} | |
}, | |
sample: { | |
invoke: { | |
src: 'sample', | |
onDone: [ | |
{ | |
target: 'audit', | |
cond: { | |
type: 'toAudit', | |
riskcategories: ['medium', 'high'] | |
} | |
}, | |
{ | |
target: 'success', | |
} | |
], | |
onError: 'failure' | |
} | |
}, | |
audit: { | |
on: { | |
STARTPROGRESS: 'inAudit' | |
} | |
}, | |
inAudit: { | |
on: { | |
REQUESTDOCUMENTS: 'documentsRequested', | |
FORWARDTOAML: 'toAMLForwarded', | |
DENY: 'open', | |
SUCCESS: 'success' | |
} | |
}, | |
documentsRequested: { | |
on: { | |
DATAAMENDED: 'audit', | |
DENY: 'denied' | |
} | |
}, | |
toAMLForwarded: { | |
on: { | |
ACCEPT: 'success', | |
DENY: 'denied' | |
} | |
}, | |
overdue: { | |
type: 'final' | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
type: 'final' | |
}, | |
denied: { | |
type: 'final' | |
} | |
}, | |
}, { | |
guards: { | |
toAudit: (context, event, { cond }) => cond.riskcategories.includes(context.riskcategory) || context.audit, | |
}, | |
services: { | |
startService: (context, event) => { | |
if (context.error) { | |
context.errorReason = 'customerDeleted'; | |
throw new Error(context.errorReason); | |
} | |
context.exportDate = new Date(); | |
console.log('Print registry link on next invoice.') | |
}, | |
riskEvaluation: (context, event) => { | |
//context.riskcategory = 'low'; | |
console.log('evaluate risk'); | |
}, | |
sample: (context, event) => { | |
//context.control = true; | |
console.log('decide for sample'); | |
} | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment