Last active
August 27, 2019 05:26
-
-
Save jesstelford/6a25309b09bd2a70a9a678ca9ee7fa2b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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