Skip to content

Instantly share code, notes, and snippets.

@bjorntheart
Created April 30, 2021 10:39
Show Gist options
  • Save bjorntheart/f77cc765e8c7c94c9bdd994f81a91fbb to your computer and use it in GitHub Desktop.
Save bjorntheart/f77cc765e8c7c94c9bdd994f81a91fbb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const policyMachine = Machine(
{
id: 'policy',
initial: 'idle',
context: {
policy: "",
},
states: {
idle: {
on: {
FETCH: {
target: "loading"
}
}
},
loading: {
invoke: {
id: 'fetchPolicy',
src: (context, event) => fetchPolicy(context.formData),
onDone: {
target: 'success',
actions: assign({ policy: (context, event) => event.data })
},
onError: {
target: 'failure',
actions: assign({ error: (context, event) => event.data })
}
}
},
success: {},
failure: {
on: {
RETRY: 'loading'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment