Last active
October 11, 2019 21:11
-
-
Save adamscott/06d61eb3c3908c95dee4a2370f8dec13 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const machine = Machine({ | |
initial: "uninitialized", | |
context: { | |
direction: "next", | |
isTemporary: false, | |
isValidated: false, | |
hasIndustry: false, | |
hasSniffed: false | |
}, | |
states: { | |
uninitialized: { | |
on: { | |
INIT: [ | |
{ | |
target: "signup", | |
cond: "isTemporary" | |
}, | |
{ | |
target: "sniffer", | |
cond: "hasNotSniffed" | |
}, | |
{ | |
target: "validate", | |
cond: "isNotValidated" | |
}, | |
{ | |
target: "industry", | |
cond: "hasNotIndustry" | |
}, | |
"objective" | |
] | |
} | |
}, | |
signup: { | |
on: { | |
NEXT: [ | |
{ | |
target: "sniffer", | |
actions: ["goNext"], | |
cond: "hasNotSniffed" | |
}, | |
{ | |
target: "validate", | |
actions: ["goNext"] | |
} | |
] | |
} | |
}, | |
sniffer: { | |
on: { | |
NEXT: [ | |
{ | |
target: "validate", | |
actions: ["goNext"], | |
cond: "isNotValidated" | |
}, | |
{ | |
target: "industry", | |
actions: ["goNext"], | |
cond: "hasNotIndustry" | |
}, | |
{ | |
target: "objective", | |
actions: ["goNext"] | |
} | |
] | |
}, | |
exit: [ | |
assign({ | |
hasSniffed: () => true | |
}) | |
] | |
}, | |
validate: { | |
on: { | |
BACK: [ | |
{ | |
target: "signup", | |
actions: ["goBack"], | |
cond: "isTemporary" | |
} | |
], | |
NEXT: [ | |
{ | |
target: "industry", | |
actions: ["goNext"], | |
cond: "hasNotIndustry" | |
}, | |
{ | |
target: "objective", | |
actions: ["goNext"] | |
} | |
] | |
} | |
}, | |
industry: { | |
on: { | |
BACK: [ | |
{ | |
target: "validate", | |
actions: ["goBack"], | |
cond: "isNotValidated" | |
}, | |
{ | |
target: "signup", | |
actions: ["goBack"], | |
cond: "isTemporary" | |
} | |
], | |
NEXT: [ | |
{ | |
target: "objective", | |
actions: ["goNext"] | |
} | |
] | |
} | |
}, | |
objective: { | |
on: { | |
BACK: [ | |
{ | |
target: "industry", | |
actions: ["goBack"], | |
cond: "hasNotIndustry" | |
}, | |
{ | |
target: "validate", | |
actions: ["goBack"], | |
cond: "isNotValidated" | |
}, | |
{ | |
target: "signup", | |
actions: ["goBack"], | |
cond: "isTemporary" | |
} | |
], | |
NEXT: { | |
target: "browse", | |
actions: ["goNext"] | |
} | |
} | |
}, | |
browse: { | |
on: { | |
BACK: { | |
target: "objective", | |
actions: ["goBack"] | |
} | |
} | |
} | |
}, | |
on: { | |
ROUTER_ERROR: { | |
// | |
} | |
} | |
}, { | |
actions: { | |
goNext: assign({ | |
direction: (context) => context.direction = "next" | |
}), | |
goBack: assign({ | |
direction: (context) => context.direction = "back" | |
}) | |
}, | |
guards: { | |
isTemporary: (context) => context.isTemporary, | |
isNotTemporary: (context) => !context.isTemporary, | |
isValidated: (context) => context.isValidated, | |
isNotValidated: (context) => !context.isValidated, | |
hasIndustry: (context) => context.hasIndustry, | |
hasNotIndustry: (context) => !context.hasIndustry, | |
hasSniffed: (context) => context.hasSniffed, | |
hasNotSniffed: (context) => !context.hasSniffed | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment