Skip to content

Instantly share code, notes, and snippets.

@jbeast
Last active March 2, 2021 16:44
Show Gist options
  • Save jbeast/bf3b7b0020d9bc2f385d54f4f5499871 to your computer and use it in GitHub Desktop.
Save jbeast/bf3b7b0020d9bc2f385d54f4f5499871 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 workshopMachine = Machine({
id: 'workshop',
initial: 'open',
context: {
capacity: 5,
booked: 0,
staff: []
},
states: {
open: {
on: {
ADD_BOOKING: [{
actions: assign({
booked: (ctx, e) => ctx.booked + 1
}),
cond: (ctx, e) => ctx.booked === ctx.capacity - 1,
target: "full"
},
{
actions: assign({
booked: (ctx, e) => ctx.booked + 1
}),
cond: (ctx, e) => ctx.booked < ctx.capacity - 1
}],
ALLOCATE_STAFF: {
actions: assign({
staff: (ctx, e) => ["jo", "john", "jeff"]
})
},
REMOVE_FROM_CALENDAR: "ready",
CANCEL: "cancelled",
}
},
full: {
on: {
REMOVE_FROM_CALENDAR: "ready",
CANCEL: "cancelled",
}
},
ready: {
on: {
START: "started",
}
},
cancelled: {
type: "final"
},
started: {
type: "final"
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment