Last active
August 19, 2020 21:26
-
-
Save barbados-clemens/4a78aae66feab67f9e90be4423a672da 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
//https://xstate.js.org/viz/?gist=4a78aae66feab67f9e90be4423a672da | |
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const clientMachine = Machine({ | |
id: 'client', | |
initial: 'loading', | |
context: { | |
retries: 0, | |
client: undefined | |
}, | |
states: { | |
loading: { | |
on: { | |
RESOLVE: { | |
target: 'success', | |
actions: assign({ | |
retries: 0, | |
client: { | |
id: 123, | |
} | |
}) | |
}, | |
REJECT: 'failure' | |
} | |
}, | |
success: { | |
on: { | |
REFRESH: { | |
target:'loading', | |
actions: assign({ | |
retries: 0, | |
client: {} | |
}) | |
}, | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'loading', | |
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