Skip to content

Instantly share code, notes, and snippets.

@felippenardi
Last active February 1, 2020 23:09
Show Gist options
  • Save felippenardi/021097d22ad0038763b0092ad5c5f97f to your computer and use it in GitHub Desktop.
Save felippenardi/021097d22ad0038763b0092ad5c5f97f 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 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