Skip to content

Instantly share code, notes, and snippets.

@alavkx
Last active August 13, 2020 19:55
Show Gist options
  • Save alavkx/19d387e72f428116953199a7d9eb1d2b to your computer and use it in GitHub Desktop.
Save alavkx/19d387e72f428116953199a7d9eb1d2b 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 tmsMachine = Machine({
id: 'tms',
type: "parallel",
context: {
billOfLading: null,
deliveryInstructions: null,
},
states: {
remittanceStatement: {
id: "remittanceStatement",
initial: "empty",
states: {
empty: {
on: {
MARK_READY: "itemsPending"
}
},
itemsPending: {
after: {
// A day in super massive black hole
2000: "process",
// 24h
// 86400: "finalStatement"
}
},
process: {
invoke: {
src: "saveStatement",
onDone: "finalStatement",
}
},
finalStatement: {
type: "final",
entry: "emailToAccountsPayable"
}
}
},
order: {
initial: "idle",
states: {
idle: {
on: {
ORDER_CREATED: 'loadAvailable'
}
},
loadAvailable: {
initial: "unacknowledged",
states: {
unacknowledged: {
on: {
REVIEW: "reviewing"
}
},
reviewing: {
on: {
MARK_READY: "readyForPayment",
REJECT: "rejected",
}
},
readyForPayment: {
type: "final",
},
rejected: {
type: "final",
entry: "notifyAttentionRequired",
}
},
on: {
CLAIM: "claimingOrder",
},
},
claimingOrder: {
entry: "generateDocs",
invoke: {
// Updates DB
src: "createOrder",
onDone: {
target: "idle",
actions: ["sendEmailConfirmation"]
}
}
}
}},
}
}, {
generateDocs: assign({
billOfLading: "data/pdf",
deliveryInstructions: "data/pdf?"
}),
saveStatement: () => null // DB save
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment