Last active
April 3, 2020 13:18
-
-
Save She-Codes/6010a095360d3d779eba074d230f62a5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 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