Skip to content

Instantly share code, notes, and snippets.

@abhayarawal
Last active May 25, 2021 11:03
Show Gist options
  • Save abhayarawal/3bd758b2913928b0dba2bc41dbafd759 to your computer and use it in GitHub Desktop.
Save abhayarawal/3bd758b2913928b0dba2bc41dbafd759 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 signUpMachine = Machine({
id: 'signup',
initial: 'start',
context: {
dogs: []
},
states: {
start: {
on: {
next: 'gender'
}
},
gender: {
on: {
back: 'start',
next: 'age'
}
},
age: {
on: {
back: 'gender',
next: 'breed'
}
},
breed: {
on: {
back: 'age',
next: 'food'
}
},
food: {
on: {
back: 'breed',
next: 'eater'
}
},
eater: {
on: {
back: 'food',
next: 'body'
}
},
body: {
on: {
back: 'eater',
next: 'weight'
}
},
weight: {
on: {
back: 'body',
next: 'activity'
}
},
activity: {
on: {
back: 'weight',
next: 'allergy'
}
},
allergy: {
on: {
back: 'activity',
next: [{
cond: 'isAllergicToAll',
target: 'allergy'
}, {
cond: 'limitedOrNoAllergy',
target: 'health'
}]
}
},
health: {
on: {
back: 'allergy',
next: [{
cond: 'conflictingHealthIssues',
target: 'health'
}, {
cond: 'noConflictingHealthIssues',
target: 'snacks'
}]
},
initial: 'noHealthIssues',
states: {
noHealthIssues: {
on: {
toggle: 'healthIssues'
}
},
healthIssues: {
on: {
toggle: 'noHealthIssues',
}
}
}
},
snacks: {
on: {
back: 'health',
next: 'postcode'
}
},
postcode: {
on: {
back: 'snacks',
next: [{
cond: 'validPostCode',
target: 'email'
}, {
cond: 'invalidPostCode',
target: 'postcode'
}]
}
},
email: {
on: {
back: 'postcode',
next: {
type: 'final'
}
}
}
}
}, {
guards: {
isAllergicToAll: () => false,
limitedOrNoAllergy: () => true,
conflictingHealthIssues: () => false,
noConflictingHealthIssues: () => true,
validPostCode: () => true,
invalidPostCode: () => false
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment