Skip to content

Instantly share code, notes, and snippets.

@nrakochy
Last active February 7, 2020 18:11
Show Gist options
  • Save nrakochy/3fd75e8f5af091f968172ac1b9edcfe0 to your computer and use it in GitHub Desktop.
Save nrakochy/3fd75e8f5af091f968172ac1b9edcfe0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const ReservationWO = {
id: "ReservationWO",
initial: "pending",
context: {},
states: {
pending: {
on: { LEAD_TIME: "work_in_progress",
START_WORK: "work_in_progress"}
},
work_in_progress: {
on: { COMPLETE_WORK: "work_complete", CANCELLED: "cancelled" }
},
work_complete: {
type: "final"
},
cancelled: {
type: "final"
}
}
};
const SingleEvent = {
id: "SingleEvent",
initial: "hold",
context: {},
states: {
available: {},
tentative: {
},
busy: {
on: { }
},
hold_pending_approval: {
on: {
UPSERT_CHILDREN: 'busy',
REJECT: 'deleted'}
},
hold: {
on: { NEEDS_APPROVAL: "hold_pending_approval",
UPSERT_CHILDREN: 'busy'}
},
available: {},
deleted: {
type: "final"
},
completed: {
type: "final"
},
}
};
const RecurrenceDefinition = {
id: "RecurrenceDefinition",
initial: "draft",
context: {},
states: {
draft: {
on: {SUBMIT: 'submitted'}
},
submitted: {
on: { APPROVE: "pending",
NO_APPROVAL_NEEDED: "pending"}
},
pending: {
on: { UPSERT_CHILDREN: "processed" }
},
processed: {
type: 'final'
}
}
};
const Reservation = {
id: "Reservation",
initial: "draft",
context: {
reservations: [{ id: 1 }]
},
states: {
draft: {
on: {
SUBMIT: "submitted"
}
},
submitted: {
on: {
NEEDS_APPROVAL: "pending_approval",
NO_APPROVAL_NEEDED: "pending"
}
},
pending_approval: {
on: {
APPROVE: "pending",
REJECT: "rejected"
}
},
pending: {
on: {
UPSERT_CHILDREN: "processed"
}
},
processed: {
on: {
UPDATE_SINGLE_EXCEPTION: "pending_update",
UPDATE_ALL_FUTURE_EVENTS: "pending_update",
UPDATE_ALL_OCCURRENCES: "pending_update"
}
},
pending_update: {
on: {
NEEDS_APPROVAL: "pending_update_approval",
NO_APPROVAL_NEEDED: "pending"
}
},
pending_update_approval: {
on: {
APPROVE: "pending",
REJECT_UPDATE: "processed"
}
},
rejected: {
type: "final"
}
}
};
const container = {
id: "Recurrence Event Generator",
initial: "draft",
type: "parallel",
context: {},
states: {
Reservation,
RecurrenceDefinition,
SingleEvent,
ReservationWO
}
};
const mach = Machine(container);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment