Created
March 20, 2020 18:53
-
-
Save jlengstorf/12a349643a70a8b09c7f7841b5168284 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 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