Last active
October 29, 2020 23:44
-
-
Save MarceloAlves/8f2bf23e10bd174c5ce9f1917141585b 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 reportMachine = Machine({ | |
id: 'reportGallery', | |
context: { | |
tab: 'gallery' | |
}, | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
'': [ | |
{ cond: (ctx) => ctx.tab === 'gallery', target: 'gallery' }, | |
{ cond: (ctx) => ctx.tab === 'favorites', target: 'favorites' }, | |
], | |
}, | |
}, | |
gallery: { | |
initial: 'view', | |
states: { | |
view: { | |
on: { | |
FAVORITE: 'favorite', | |
}, | |
}, | |
favorite: { | |
invoke: { | |
id: 'favoriteReport', | |
src: 'favoriteReport', | |
onDone: 'notifySuccess', | |
onError: 'notifyError', | |
}, | |
}, | |
notifySuccess: { | |
invoke: { | |
id: 'notifyFavoriteSuccess', | |
src: 'notifyFavoriteSuccess', | |
onDone: { target: 'view' }, | |
}, | |
}, | |
notifyError: { | |
invoke: { | |
id: 'notifyFavoriteError', | |
src: 'notifyFavoriteError', | |
onDone: { target: 'view' }, | |
}, | |
}, | |
}, | |
}, | |
favorites: { | |
initial: 'view', | |
states: { | |
view: {}, | |
remove: {}, | |
edit: {}, | |
}, | |
}, | |
}, | |
}, { | |
services: { | |
favoriteReport: async () => {}, | |
notifyFavoriteSuccess: async (message) => { | |
// need dynamic message to call notify function | |
console.log('Notify') | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment