Last active
May 12, 2021 09:44
-
-
Save lazybean/95966efea2b5510b6cc30a4a13215c0e 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 fetchMachine = Machine({ | |
id: 'simulation', | |
initial: 'idle', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
SIMULATE: 'creating' | |
} | |
}, | |
creating: { | |
entry: ['createPlaceholder'], | |
exit: ['removePlaceholder'], | |
on: { | |
RESOLVE: 'polling', | |
REJECT: 'failure' | |
}, | |
}, | |
polling: { | |
on: { | |
SUCCESS: 'success', | |
RUNNING: 'polling', | |
}, | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
'after 5s': 'request' | |
} | |
}, | |
request: { | |
on: { | |
response: 'response' | |
} | |
}, | |
response: { | |
on: { | |
'after 5s': 'request' | |
} | |
}, | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'creating', | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment