Skip to content

Instantly share code, notes, and snippets.

@She-Codes
Last active April 3, 2020 13:18
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 She-Codes/6010a095360d3d779eba074d230f62a5 to your computer and use it in GitHub Desktop.
Save She-Codes/6010a095360d3d779eba074d230f62a5 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 rtsMachine = Machine({
id: 'rts',
initial: 'idle',
states: {
idle: {
on: {
OPEN: 'ready'
}
},
ready: {
on: {
REQUEST: 'loading',
CANCEL: 'loading'
}
},
loading: {
on: {
RESOLVE: 'success',
ERROR: 'failure'
}
},
cancelled: {
// show cancelled success
on: {
CLOSE: 'idle',
REQUEST: 'loading'
}
},
requested: {
initial: 'open',
// show requested success
// CLOSE -> still stay in requested
// but remove menu message
states: {
open: {
on: {
CLOSE: 'closed',
CANCEL: '#rts.loading'
}
},
closed: {
on: {
OPEN: 'open'
}
}
}
},
success: {
// here you have to decide if you are going to
// cancelled or requested
on: {
// null event '' always occurs once state is entered
'': [
{ target: 'cancelled', cond: () => false },
{ target: 'requested', cond: () => true }
]
}
},
failure: {
on: {
REQUEST: 'loading',
CANCEL: 'loading'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment