Last active
February 1, 2020 23:09
-
-
Save felippenardi/021097d22ad0038763b0092ad5c5f97f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const contentEditorMachine = Machine({ | |
id: 'editor', | |
initial: 'unknown', | |
context: { | |
hasLive: true, | |
hasDraft: false | |
}, | |
states: { | |
'unknown': { | |
on: { | |
'': [ | |
{ target: 'editingDraft', cond: 'hasDraft' }, | |
{ target: 'viewing', cond: 'hasLive' }, | |
{ target: 'creatingDraft' } | |
]} | |
}, | |
viewing: { | |
on: { | |
CREATE_DRAFT: 'creatingDraft' | |
} | |
}, | |
creatingDraft: { | |
on: { | |
SAVE: 'saved' | |
} | |
}, | |
editingDraft: { | |
on: { | |
SAVE: 'saved' | |
} | |
}, | |
saved: { | |
onEntry: 'saveDraft', | |
on: { | |
EDIT: 'editingDraft', | |
PUBLISH: 'published', | |
} | |
}, | |
published: { | |
on: { | |
VIEW: 'viewing', | |
EDIT_DRAFT: { | |
target: 'editingDraft', | |
cond: 'hasDraft' | |
}, | |
CREATE_DRAFT: 'editingDraft' | |
} | |
}, | |
} | |
}, { | |
actions: { | |
saveDraft: assign({ | |
hasDraft: () => true | |
}) | |
}, | |
guards: { | |
hasLive: ctx => ctx.hasLive, | |
hasDraft: ctx => ctx.hasDraft | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment