Skip to content

Instantly share code, notes, and snippets.

@victor36max
Last active September 12, 2019 05:30
Show Gist options
  • Save victor36max/7a1b3c08a172b656f1249e8010c34538 to your computer and use it in GitHub Desktop.
Save victor36max/7a1b3c08a172b656f1249e8010c34538 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 machine = Machine({
id: 'collapsible',
initial: 'closed',
states: {
closed: {
on: {
OPEN: {
target: 'opening',
actions: 'closedToOpeningAnimation',
},
},
},
opening: {
invoke: {
src: 'openingAnimation',
onDone: 'opened',
},
on: {
CLOSE: 'closing',
},
},
opened: {
entry: 'openedAnimation',
on: {
CLOSE: {
target: 'closing',
actions: 'openedToClosingAnimation',
},
},
},
closing: {
invoke: {
src: 'closingAnimation',
onDone: 'closed',
},
on: {
OPEN: 'opening',
},
},
},
}, {
services: {
openingAnimation: () => new Promise(resolve => setTimeout(resolve, 2000)),
closingAnimation: () => new Promise(resolve => setTimeout(resolve, 2000)),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment