Skip to content

Instantly share code, notes, and snippets.

@Jaredk3nt
Last active February 24, 2021 19:42
Show Gist options
  • Save Jaredk3nt/f0d2a7f37ca1e6f0549054143a66a191 to your computer and use it in GitHub Desktop.
Save Jaredk3nt/f0d2a7f37ca1e6f0549054143a66a191 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const multiPitchMachine = Machine({
id: 'multi-pitch',
initial: 'idle',
context: {
pitches: 0
},
states: {
idle: {
on: {
BELAY: 'belaying',
CLIMB: 'climbing',
RAPPEL: 'rappelling'
}
},
belaying: {
on: {
TAKE: 'taking',
SAFE: 'climbing'
}
},
taking: {
on: {
BELAY: 'belaying'
}
},
climbing: {
on: {
TAKE: 'hanging',
TOP: {
target: 'idle',
actions: assign({
pitches: (context, event) => context.pitches + 1
})
},
TOPOUT: {
target: 'success',
actions: assign({
pitches: (context, event) =>
context.pitches + 1
})
}
}
},
hanging: {
on: {
CLIMB: 'climbing',
LOWER: 'lowering'
}
},
lowering: {
on: {
GROUND: 'idle'
}
},
rappelling: {
on: {
GROUND: 'bailed'
}
},
success: {
type: 'final'
},
bailed: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment