Skip to content

Instantly share code, notes, and snippets.

@badgeek
Created January 31, 2020 09:50
Show Gist options
  • Save badgeek/87f425f33e8ce3a87ee75ab4cd6618d1 to your computer and use it in GitHub Desktop.
Save badgeek/87f425f33e8ce3a87ee75ab4cd6618d1 to your computer and use it in GitHub Desktop.

Revisions

  1. badgeek created this gist Jan 31, 2020.
    59 changes: 59 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    const BasicMachine = Machine({
    id: "basicmachine",
    initial: "inactive",
    context: {},
    states: {
    copying : {
    id: "copying",
    initial: "loading",
    states: {
    loading: {
    invoke: {
    id: "getscheduledata",
    src: "loadscheduleservice",
    onDone: {
    target: "creating",
    actions: ["assignScheduleData"]
    },
    onError: {
    target: "#basicmachine.inactive",
    actions: "debug"
    }
    }
    },
    creating: {
    invoke: {
    id: "createschedule",
    src: "createscheduleservice",
    onDone: {
    target: "#basicmachine.inactive",
    actions: "debug"
    },
    onError: {
    target: "#basicmachine.inactive",
    actions: "debug"
    }
    }
    }},
    },
    inactive: {
    on: {
    DUPLICATE: {
    target: "copying"
    },
    TOGGLE: {
    target: "active",
    actions: () => toast.success("go to active")
    }
    }
    },
    active: {
    on: {
    TOGGLE: {
    target: "inactive",
    actions: () => toast.success("go to inactive")
    }
    }
    }
    }
    });