Skip to content

Instantly share code, notes, and snippets.

@severnsc
Last active January 20, 2020 20:28
Show Gist options
  • Save severnsc/106f0e4481965c59223535901b3406c9 to your computer and use it in GitHub Desktop.
Save severnsc/106f0e4481965c59223535901b3406c9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const signupStates = {
id: "sign_up",
initial: "sign_up",
states: {
sign_up: {
on: {
SUCCESS: "select_location",
ERROR: {
target: "sign_up",
actions: assign({
error: (context, event) => "Signup error"
})
}
}
},
select_location: {
on: {
SUCCESS: "valid_location",
REJECT: "invalid_location"
}
},
valid_location: {
type: "final"
},
invalid_location: {
on: {
OPT_IN: "location_opt_in",
OPT_OUT: "location_opt_out"
}
},
location_opt_in: {
type: "final"
},
location_opt_out: {
type: "final"
}
}
};
const introToVettingStates = {
id: "intro_to_vetting",
initial: "decision",
states: {
decision: {
on: {
TEXT: "text",
AUDIO: "audio",
VIDEO: "video"
}
},
video: {
on: {
WATCHED: "complete"
}
},
audio: {
on: {
LISTENED: "complete"
}
},
text: {
on: {
READ: "complete"
}
},
complete: {
type: "final"
}
}
}
const uploadStates = {
initial: "idle",
context: {
retries: 0
},
states: {
idle: {
on: {
BEGIN: "uploading"
}
},
uploading: {
on: {
REJECT: "failure",
RESOLVE: "success"
}
},
success: {
type: "final"
},
failure: {
on: {
RETRY: {
target: "uploading",
action: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
}
const failVettingStates = {
id: "fail_vetting",
initial: "failed",
states: {
failed: {
on: {
OPT_IN: "opt_in",
OPT_OUT: "opt_out"
}
},
opt_in: {
type: "final"
},
opt_out: {
type: "final"
}
}
}
const failEnglishStates = {
id: "fail_english",
initial: "failed",
states: {
failed: {
on: {
OPT_IN: "opt_in",
OPT_OUT: "opt_out"
}
},
opt_in: {
type: "final"
},
opt_out: {
type: "final"
}
}
}
const codeChallengeStates = {
id: "code_challenge",
initial: "instructions",
states: {
instructions: {
on: {
PROCEED: "upload"
}
},
upload: {
id: "code_challenge_upload",
...uploadStates,
on: {
UPLOADED: "wait_for_review"
}
},
wait_for_review: {
type: "final"
}
}
}
const scheduleStates = {
initial: "schedule",
states: {
schedule: {
on: {
ERROR: {
target: "schedule",
actions: assign({
error: (context, event) => "Scheduling error"
})
},
SUCCESS: "scheduled"
}
},
scheduled: {
on: {
REQUEST_RESCHEDULE: "schedule",
CANCEL: "schedule"
}
}
}
}
const techInterviewStates = {
id: "tech_interview",
initial: "schedule_interview",
states: {
schedule_interview: {
on: {
SUCCESS: "perform_interview",
},
...scheduleStates
},
perform_interview: {
on: {
FAILURE: "schedule_interview",
SUCCESS: "grade_interview"
}
},
grade_interview: {
on: {
GRADED: "complete"
}
},
complete: {
type: "final"
}
}
}
const culturalVettingStates = {
id: "cultural_vetting",
initial: "ready_to_start",
states: {
ready_to_start: {
on: {
START: "in_progress"
}
},
in_progress: {
on: {
FINISH: "complete"
}
},
complete: {
type: "final"
}
}
}
const preInterviewStates = {
id: "vetting",
type: "parallel",
states: {
code_challenge: {
...codeChallengeStates
},
cultural_vetting: {
...culturalVettingStates
}
}
}
const onboardingStates = {
id: "onboarding",
initial: "explanation",
states: {
explanation: {
on: {
PROCEED: "schedule_onboarding"
}
},
schedule_onboarding: {
on: {
SUCCESS: "perform_onboarding"
},
...scheduleStates
},
perform_onboarding: {
on: {
FAILURE: "schedule_onboarding",
SUCCESS: "complete"
}
},
complete: {
type: "final"
}
}
}
const SignupMachine = Machine({
id: "signup_flow",
initial: "sign_up",
context: {
error: ""
},
states: {
sign_up: {
...signupStates,
on: {
SUCCESS: "intro_to_vetting"
}
},
intro_to_vetting: {
...introToVettingStates,
on: {
PROCEED: "pre_interview"
}
},
pre_interview: {
...preInterviewStates,
on: {
FAIL: "fail_vetting",
FAIL_ENGLISH: "fail_english",
PASS: "tech_interview"
}
},
fail_vetting: {
...failVettingStates
},
fail_english: {
...failEnglishStates
},
tech_interview: {
...techInterviewStates,
on: {
FAIL: "fail_vetting",
FAIL_ENGLISH: "fail_english",
PASS: "onboarding"
}
},
onboarding: {
...onboardingStates,
on: {
COMPLETE: "dashboard"
}
},
dashboard: {
id: "dashboard",
type: "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment