Skip to content

Instantly share code, notes, and snippets.

@jesstelford
Last active August 27, 2019 05:26
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 jesstelford/6a25309b09bd2a70a9a678ca9ee7fa2b to your computer and use it in GitHub Desktop.
Save jesstelford/6a25309b09bd2a70a9a678ca9ee7fa2b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Vocal 'publishStatus' state machine
const machineId = 'publishing';
const publishMachine = Machine(
{
id: machineId,
initial: 'draft',
states: {
uninitialized: {
on: {
draft: 'draft',
},
},
draft: {
on: {
needs_review: [
{ target: 'needs_review', cond: 'isAdmin' },
{ target: 'needs_review', cond: 'isAuthor' },
],
archived: [
{ target: 'archived', cond: 'isAdmin' },
{ target: 'archived', cond: 'isAuthor' },
],
},
},
needs_review: {
on: {
in_review: [{ target: 'in_review', cond: 'isAdmin' }],
archived: [{ target: 'archived', cond: 'isAdmin' }],
},
},
in_review: {
on: {
published: [{ target: 'published', cond: 'isAdmin' }],
not_approved: [{ target: 'not_approved', cond: 'isAdmin' }],
archived: [{ target: 'archived', cond: 'isAdmin' }],
},
},
not_approved: {
on: {
draft: [{ target: 'draft', cond: 'isAdmin' }],
needs_review: [{ target: 'needs_review', cond: 'isAdmin' }],
archived: [{ target: 'archived', cond: 'isAdmin' }],
},
},
published: {
on: {
draft: [{ target: 'draft', cond: 'isAdmin' }],
archived: [{ target: 'archived', cond: 'isAdmin' }],
},
},
archived: {
on: {
draft: [{ target: 'draft', cond: 'isAdmin' }],
},
},
},
},
{
guards: {
isAdmin: () => true,
isAuthor: () => true,
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment