Created
July 30, 2020 12:34
-
-
Save edvinerikson/5c5090ed8d0abe6a8f30d156d5ea4522 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
const duplicateAccountCheckMachine = Machine({ | |
id: "duplicateAccountCheck", | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
OPEN: "started" | |
} | |
}, | |
started: { | |
on: { | |
CLOSE: "finishing" | |
} | |
}, | |
finishing: { | |
on: { | |
ABORT: "idle", | |
PERSIST: "persisting", | |
BACK: "started", | |
TOGGLE_RESULT: { | |
target: "finishing", | |
actions: assign({ | |
result: context => { | |
return context.result === "SUCCESS" ? "FAIL" : "SUCCESS"; | |
} | |
}) | |
}, | |
TOGGLE_DEVICE_CHECK: { | |
target: "finishing", | |
actions: assign({ | |
deviceCheckCompleted: context => { | |
return !context.deviceCheckCompleted; | |
}, | |
comment: () => { | |
return null; | |
} | |
}) | |
}, | |
CHANGE_COMMENT: { | |
target: "finishing", | |
actions: assign({ | |
comment: (context, event) => { | |
return event.comment; | |
} | |
}) | |
} | |
} | |
}, | |
persisting: { | |
on: { | |
REJECT: "failure", | |
RESOLVE: "finished" | |
}, | |
invoke: { | |
id: "persist", | |
src: context => callback => { | |
const { | |
environment, | |
playerId, | |
result, | |
deviceCheckCompleted, | |
comment | |
} = context; | |
if (playerId == null) { | |
callback("REJECT"); | |
return; | |
} | |
const disposable = commitMutation< | |
DobMobCheckMachineCreateCheckMutation | |
>(environment, { | |
mutation: graphql` | |
mutation DobMobCheckMachineCreateCheckMutation( | |
$input: CreatePlayerDuplicateAccountCheckInput! | |
) { | |
createPlayerDuplicateAccountCheck(input: $input) { | |
__typename | |
} | |
} | |
`, | |
variables: { | |
input: { | |
playerId, | |
result, | |
deviceCheckCompleted, | |
comment | |
} | |
}, | |
onCompleted: (response, errors) => { | |
if ( | |
(errors != null && errors.length > 0) || | |
response.createPlayerDuplicateAccountCheck.__typename === | |
"CreatePlayerDuplicateAccountCheckErrorPayload" | |
) { | |
callback("REJECT"); | |
} else { | |
callback("RESOLVE"); | |
} | |
}, | |
onError: () => { | |
callback("REJECT"); | |
} | |
}); | |
return () => disposable.dispose(); | |
} | |
} | |
}, | |
finished: { | |
initial: "closed", | |
states: { | |
open: { | |
on: { | |
CLOSE: "closed" | |
} | |
}, | |
closed: { | |
on: { | |
OPEN: "open" | |
} | |
} | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: "persisting" | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment