Skip to content

Instantly share code, notes, and snippets.

@chnirt
Last active April 3, 2020 08:17
Show Gist options
  • Save chnirt/40e6e3c9ef2450b0cd9344e257866d92 to your computer and use it in GitHub Desktop.
Save chnirt/40e6e3c9ef2450b0cd9344e257866d92 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 fetchMachine = Machine({
id: 'taskMachine',
initial: 'IDLE',
context: {
initial: 'IDLE',
permissions: ["TASK_CREATE"]
},
states: {
IDLE: {
on: {
CREATE_TASK: {
target: 'DRAFT',
cond: "createTaskPermissions"
// actions: assign({
// initial: (context, event) => context.initial = 'DRAFT'
// })
}
}
},
DRAFT: {
on: {
REQUEST_APPROVE: 'NEED_APPROVE',
}
},
NEED_APPROVE: {
on: {
APPROVE: "OFFICIAL",
DISAPPROVE: "DRAFT",
CANCEL_NEED_APPROVE: "DRAFT"
}
},
OFFICIAL: {
on: {
PULL_TASK: "RUNNING",
CANCEL_TASK: "NEED_APPROVE"
}
},
RUNNING: {
on: {
RETURN_TASK: "OFFICIAL",
REQUEST_REVIEW: "NEED_REVIEW"
}
},
NEED_REVIEW: {
on: {
COMPLETE: "COMPLETED",
FAIL: "FAILED",
CANCEL_NEED_REVIEW: "RUNNING"
}
},
COMPLETED: {
type: "final"
},
FAILED: {
type: "final"
},
}
}, {
guards: {
createTaskPermissions: (context) => {
console.log(context.permissions.some("CREATE_TASK"))
return true
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment