Created
July 4, 2020 13:45
-
-
Save ritwizsinha/5df063f9c7c4b7923858accf9d669e2c 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 stateMachine = Machine({ | |
initial: "idle", | |
context: { | |
msg: "" | |
}, | |
states: { | |
idle: { | |
on: { | |
SUBMIT: [ | |
{ | |
target: "loading", | |
cond: (ctx, event) => | |
event.data.name !== "" && event.data.card !== "" | |
}, | |
{ | |
target: "error" | |
} | |
] | |
} | |
}, | |
loading: { | |
invoke: { | |
id: "doPayment", | |
src: () => fakePayment(), | |
onDone: { | |
target: "success", | |
actions: assign({ msg: (ctx, event) => event.data }) | |
}, | |
onError: { | |
target: "error", | |
actions: assign({ msg: (ctx, event) => event.data }) | |
} | |
} | |
}, | |
error: { | |
on: { | |
SUBMIT: { | |
target: "loading", | |
cond: (ctx, event) => event.data.name !== "" && event.data.card !== "" | |
} | |
} | |
}, | |
success: { | |
type: "final" | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment