Created
April 24, 2020 10:22
-
-
Save ajubin/1b93b72901cf84b716d036b612e5b360 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 fetchMachine = Machine({ | |
id: 'library', | |
initial: 'hydration', | |
strict: true, | |
context: { | |
gameUrl: undefined, | |
games: [], | |
selectedGames: [], | |
}, | |
states: { | |
hydration: { | |
invoke: { | |
id: 'async.fetchLibrary', | |
src: 'async.fetchLibrary', | |
onDone: { | |
target: 'shareHydration', | |
actions: 'ctx.addGames', | |
}, | |
onError: 'shareHydration', | |
}, | |
}, | |
shareHydration: { | |
invoke: { | |
id: 'async.getInitialShare', | |
src: 'async.getInitialShare', | |
onDone: [ | |
{ | |
cond: 'cond.emptyUrl', | |
target: 'idle', | |
}, | |
{ | |
target: 'addition.downloading', | |
actions: [ | |
'ctx.setGameUrl' | |
], | |
}, | |
], | |
onError: 'idle', | |
}, | |
}, | |
idle: { | |
on: { | |
CONFIRM: 'addition', | |
LONGPRESS_CART: { | |
target: 'deletion', | |
actions: 'ctx.selectCart', | |
}, | |
PRESS_CART: { | |
actions: ['se.goToCart'], | |
}, | |
}, | |
}, | |
addition: { | |
initial: 'idle', | |
invoke: { | |
id: 'add-back-press', | |
src: 'handleBackPress', | |
}, | |
states: { | |
idle: { | |
on: { | |
CONFIRM: { | |
cond: 'cond.urlNotEmpty', | |
target: 'downloading', | |
}, | |
}, | |
}, | |
downloading: { | |
invoke: { | |
id: 'fetch-cart', | |
src: 'fetchCart', | |
onDone: { | |
target: 'success', | |
actions: [ | |
'ctx.addGame' | |
], | |
}, | |
onError: { | |
target: 'idle', | |
actions: [ | |
'se.displayError' | |
], | |
}, | |
}, | |
}, | |
success: { | |
type: 'final', | |
}, | |
}, | |
on: { | |
WRITE: { | |
actions: 'ctx.setGameUrl', | |
}, | |
CANCEL: { | |
target: 'idle', | |
actions: 'ctx.resetUrl', | |
}, | |
LONGPRESS_CART: { | |
target: 'deletion', | |
actions: ['ctx.selectCart'], | |
}, | |
PRESS_CART: { | |
target: 'idle', | |
actions: [ | |
'ctx.resetUrl', | |
'se.goToCart', | |
], | |
}, | |
}, | |
onDone: { | |
target: 'idle', | |
actions: ['se.persist'], | |
}, | |
}, | |
deletion: { | |
invoke: { | |
id: 'svc.backPressListener', | |
src: 'svc.backPressListener', | |
}, | |
on: { | |
PRESS_CART: { | |
actions: 'ctx.selectCart', | |
}, | |
LONGPRESS_CART: { | |
actions: 'ctx.selectCart', | |
}, | |
CONFIRM: { | |
target: 'idle', | |
actions: ['ctx.removeSelectedCarts', 'se.persist'], | |
}, | |
CANCEL: { | |
target: 'idle', | |
actions: ['ctx.resetSelectedCarts'], | |
}, | |
}, | |
}, | |
}, | |
invoke: { | |
id: 'listen-share', | |
src: 'svc.shareListener', | |
}, | |
on: { | |
SHARE: { | |
target: 'addition.downloading', | |
actions: [ | |
'ctx.setGameUrl', | |
], | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment