|
|
@@ -0,0 +1,143 @@
|
|
|
+import { createMachine } from "xstate";
|
|
|
+
|
|
|
+export const machine = createMachine(
|
|
|
+ {
|
|
|
+ id: "trackTime",
|
|
|
+ initial: "choose",
|
|
|
+ states: {
|
|
|
+ choose: {
|
|
|
+ on: {
|
|
|
+ SLEEPING: {
|
|
|
+ target: "sleeping",
|
|
|
+ },
|
|
|
+ MIXED: {
|
|
|
+ target: "mixed",
|
|
|
+ },
|
|
|
+ FAST: {
|
|
|
+ target: "fasting",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ sleeping: {
|
|
|
+ initial: "TO_START",
|
|
|
+ states: {
|
|
|
+ TO_START: {
|
|
|
+ on: {
|
|
|
+ start: {
|
|
|
+ target: "SLEEP_ON_GOING",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ SLEEP_ON_GOING: {
|
|
|
+ on: {
|
|
|
+ abandon: {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ end: {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ DONE: {},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mixed: {
|
|
|
+ initial: "TO_START",
|
|
|
+ states: {
|
|
|
+ TO_START: {
|
|
|
+ on: {
|
|
|
+ start_fast: {
|
|
|
+ target: "IN_PROG1",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ IN_PROG1: {
|
|
|
+ on: {
|
|
|
+ "abandon_fast": {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ "start_sleep": {
|
|
|
+ target: "IN_PROG2",
|
|
|
+ },
|
|
|
+ "end fast(skip_start_sleep)": {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ DONE: {},
|
|
|
+ IN_PROG2: {
|
|
|
+ on: {
|
|
|
+ "abandon_sleep": {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ "end fast(skip_end_sleep)": {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ "end_sleep": {
|
|
|
+ target: "IN_PROG3",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ IN_PROG3: {
|
|
|
+ on: {
|
|
|
+ abandon_fast: {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ end_fast: {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ fasting: {
|
|
|
+ initial: "TO_START",
|
|
|
+ states: {
|
|
|
+ TO_START: {
|
|
|
+ on: {
|
|
|
+ start: {
|
|
|
+ target: "FAST_ON_GOING",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ FAST_ON_GOING: {
|
|
|
+ on: {
|
|
|
+ end: {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ abandon: {
|
|
|
+ target: "DONE",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ DONE: {},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ schema: {
|
|
|
+ events: {} as
|
|
|
+ | { type: "start" }
|
|
|
+ | { type: "abandon" }
|
|
|
+ | { type: "SLEEPING" }
|
|
|
+ | { type: "FAST" }
|
|
|
+ | { type: "MIXED" }
|
|
|
+ | { type: "end" }
|
|
|
+ | { type: "start_sleep" }
|
|
|
+ | { type: "end fast(skip_start_sleep)" }
|
|
|
+ | { type: "end fast(skip_end_sleep)" }
|
|
|
+ | { type: "end_sleep" }
|
|
|
+ | { type: "abandon_sleep" }
|
|
|
+ | { type: "abandon_fast" }
|
|
|
+ | { type: "start_fast" }
|
|
|
+ | { type: "end_fast" },
|
|
|
+ },
|
|
|
+ predictableActionArguments: true,
|
|
|
+ preserveActionOrder: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ actions: {},
|
|
|
+ services: {},
|
|
|
+ guards: {},
|
|
|
+ delays: {},
|
|
|
+ },
|
|
|
+);
|