Created
April 30, 2021 10:39
-
-
Save bjorntheart/f77cc765e8c7c94c9bdd994f81a91fbb 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
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