Skip to content

Instantly share code, notes, and snippets.

@MarceloAlves
Last active October 29, 2020 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarceloAlves/8f2bf23e10bd174c5ce9f1917141585b to your computer and use it in GitHub Desktop.
Save MarceloAlves/8f2bf23e10bd174c5ce9f1917141585b 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 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