Skip to content

Instantly share code, notes, and snippets.

@matjahs
Created June 20, 2022 14:25
Show Gist options
  • Save matjahs/f52535dfba1fb72a00eccf080b96e667 to your computer and use it in GitHub Desktop.
Save matjahs/f52535dfba1fb72a00eccf080b96e667 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 IssueStateType = {
INACTIVE: "INACTIVE",
PENDING: "PENDING",
NEW: "NEW",
READY_FOR_SPRINT: "READY_FOR_SPRINT",
PROGRESS: "PROGRESS",
REVIEW: "REVIEW",
TEST: "TEST",
DONE: "DONE",
CLOSED: "CLOSED",
};
const IssueEventType = {
ACTIVATE: "ACTIVATE",
APPROVE_PR: "APPROVE_PR",
TO_NEW: "TO_NEW",
TO_READY_FOR_SPRINT: "TO_READY_FOR_SPRINT",
TO_PROGRESS: "TO_PROGRESS",
TO_REVIEW: "TO_REVIEW",
TO_TEST: "TO_TEST",
TO_DONE: "TO_DONE",
CLOSE: "CLOSE",
};
const fetchMachine = Machine({
context: {
READY_FOR_SPRINT: false,
PROGRESS: false,
REVIEW: false,
TEST: false,
DONE: false,
NEW: false,
CLOSED: false,
PENDING: false,
INACTIVE: false,
},
initial: IssueStateType.INACTIVE,
states: {
INACTIVE: {
type: "atomic",
on: {
ACTIVATE: {
target: "PENDING",
},
},
},
PENDING: {
type: "parallel",
states: {
READY_FOR_SPRINT: {
type: "compound",
initial: "unvisited",
states: {
unvisited: {
on: {
TO_READY_FOR_SPRINT: {
target: "visited",
actions: assign(context => ({
[IssueStateType.READY_FOR_SPRINT]: (context[state] = true),
message: `visited: 'TO_READY_FOR_SPRINT'`,
})),
},
},
},
visited: {
type: "final",
},
},
},
PROGRESS: {
type: "compound",
initial: "unvisited",
states: {
unvisited: {
on: {
TO_PROGRESS: {
target: "visited",
actions: assign(context => ({
[IssueStateType.PROGRESS]: (context[state] = true),
message: `visited: 'TO_READY_FOR_SPRINT'`,
})),
},
},
},
visited: {
type: "final",
},
},
},
REVIEW: {
type: "compound",
initial: "unvisited",
states: {
unvisited: {
on: {
TO_REVIEW: {
target: "visited",
actions: assign(context => ({
[IssueStateType.REVIEW]: (context[state] = true),
message: `visited: 'TO_READY_FOR_SPRINT'`,
})),
},
},
},
visited: {
type: "final",
},
},
},
TEST: {
type: "compound",
initial: "unvisited",
states: {
unvisited: {
on: {
TO_TEST: {
target: "visited",
actions: assign(context => ({
[IssueStateType.TEST]: (context[state] = true),
message: `visited: 'TO_READY_FOR_SPRINT'`,
})),
},
},
},
visited: {
type: "final",
},
},
},
DONE: {
type: "compound",
initial: "unvisited",
states: {
unvisited: {
on: {
TO_DONE: {
target: "visited",
actions: assign(context => ({
[IssueStateType.DONE]: (context[state] = true),
message: `visited: 'TO_READY_FOR_SPRINT'`,
})),
},
},
},
visited: {
type: "final",
},
},
},
},
on: {
CLOSE: {
target: "CLOSED",
},
},
onDone: {
target: "CLOSED",
},
},
CLOSED: {
initial: "validating",
states: {
validating: {
always: [
{
target: "valid",
internal: true,
cond: "isFlowValid",
},
{
target: "invalid",
internal: true,
},
],
},
valid: {
type: "final",
},
invalid: {
type: "final",
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment