Last active
March 2, 2021 16:44
-
-
Save jbeast/bf3b7b0020d9bc2f385d54f4f5499871 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 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