Skip to content

Instantly share code, notes, and snippets.

@Colubi
Created October 14, 2019 11:59
Show Gist options
  • Select an option

  • Save Colubi/f836da412aea6cc0eb6081e6af6e8931 to your computer and use it in GitHub Desktop.

Select an option

Save Colubi/f836da412aea6cc0eb6081e6af6e8931 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: "optIn",
type: "parallel",
context: {
optInState: "initial",
optInRequest: {
successState: "Success",
},
},
states: {
flow: {
initial: "initial",
states: {
initial: {
on: {
START_OPTIN: [
{
target: "progress",
in: "#optIn.session.loggedIn",
actions: ["assignOptInRequestParams"],
},
{
actions: ["assignOptInRequestParams", "displayLogin"],
},
],
},
},
progress: {
entry: "setLoading",
invoke: {
src: "requestOptIn",
onDone: {
target: "success",
actions: assign({
optInState: (_, result) => result.data,
}),
},
onError: {
target: "error",
actions: assign({
optInState: (_, result) => result.data,
}),
},
},
},
success: {
type: "final",
entry: "onOptInSuccess",
},
error: {
type: "final",
entry: "onOptInError",
},
},
},
session: {
initial: "notDetermined",
states: {
notDetermined: {
on: {
LOG_IN: {
target: "loggedIn",
},
LOG_OUT: {
target: "loggedOut",
},
},
},
loggedIn: {
on: {
LOG_OUT: {
target: "loggedOut",
},
},
},
loggedOut: {
on: {
LOG_IN: {
target: "loggedIn",
},
},
},
},
},
},
}, {
actions: {
assignOptInRequestParams: assign({
optInRequest: (_, event) => event.optInRequest,
}),
setLoading: assign({
optInState: "progress",
}),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment