Skip to content

Instantly share code, notes, and snippets.

@betocantu93
Last active January 13, 2021 16:44
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 betocantu93/9fe963715f314ede637328b5868457df to your computer and use it in GitHub Desktop.
Save betocantu93/9fe963715f314ede637328b5868457df 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 canInProgress = (context, event) => {
let {
requiresTakeFive,
workersAssigned,
dueDate,
hasTakeFive
} = context;
const baseValidations = workersAssigned && dueDate;
if(requiresTakeFive) {
return baseValidations && hasTakeFive;
}
return baseValidations;
};
const fetchMachine = Machine({
id: 'report_workflow',
initial: 'created',
context: {
workersAssigned: true,
dueDate: true,
requiresTakeFive: true,
hasTakeFive: true,
evidence: true
},
states: {
created: {
on: {
START_WORKING: {
target: 'in_progress',
cond: canInProgress
},
MARK_AS_COMPLETE: 'done',
CANCEL: 'cancel'
}
},
in_progress: {
on: {
SEND_TO_REVIEW: {
target: 'in_review',
cond: (context) => context.evidence
},
CANCEL: 'cancel'
}
},
in_review: {
on: {
APPROVE: 'done',
DECLINE: 'in_progress',
CANCEL: 'cancel'
}
},
done: {
type: 'final'
},
cancel: {
on: {
RESTORE: 'created'
}
}
}
},
{
guards: {
canInProgress
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment