Skip to content

Instantly share code, notes, and snippets.

@felippenardi
Last active February 3, 2020 18:58
Show Gist options
  • Save felippenardi/e9d06f8a2a39ad488ae7c1d30b2821bd to your computer and use it in GitHub Desktop.
Save felippenardi/e9d06f8a2a39ad488ae7c1d30b2821bd 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 editingMachine = Machine({
id: 'editingMachine',
initial: 'editing',
states: {
editing: {
id: 'editing',
on: {
SAVE: 'saving',
DISCARD: 'confirmingDiscard'
}
},
confirmingDiscard: {
on: {
CONFIRM_DISCARD: '#viewing',
CANCEL_DISCARD: '#editing'
}
},
saving: {
on: {
SUCCESS: 'viewing',
FAILURE: 'editing'
}
},
viewing: {
id: 'viewing',
type: 'final'
}
}
})
const contentMachine = Machine({
id: 'content',
initial: 'draft',
context: {
},
states: {
draft: {
id: 'draft',
initial: 'viewing',
states: {
viewing: {
on: {
OPEN_DRAFT: '#content.draft',
OPEN_LIVE: '#content.live',
EDIT: 'editing',
}
},
editing: {
invoke: {
id: 'editingDraft',
src: editingMachine,
autoForward: true,
onDone: 'viewing'
},
}
}
},
live: {
initial: 'viewing',
states: {
viewing: {
on: {
OPEN_DRAFT: '#content.draft',
OPEN_LIVE: '#content.live',
EDIT: 'editing',
}
},
editing: {
invoke: {
id: 'editingDraft',
src: editingMachine,
autoForward: true,
onDone: 'viewing'
},
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment