Skip to content

Instantly share code, notes, and snippets.

@jlengstorf
Created March 20, 2020 18:53
Show Gist options
  • Save jlengstorf/12a349643a70a8b09c7f7841b5168284 to your computer and use it in GitHub Desktop.
Save jlengstorf/12a349643a70a8b09c7f7841b5168284 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 openCartAnimation = () =>
new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 1000)
reject(false)
})
const closeCartAnimation = () =>
new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 1000)
})
const cartMachine = Machine({
id: 'cart',
initial: 'closed',
states: {
closed: {
on: {
OPEN: 'opening'
}
},
opening: {
invoke: {
src: openCartAnimation,
onDone: 'open',
onError: 'error'
}
},
open: {
on: {
CLOSE: 'closing',
}
},
closing: {
invoke: {
src: closeCartAnimation,
onDone: 'closed',
onError: 'error'
}
},
error: {
on: {
RESET: 'closed',
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment