Skip to content

Instantly share code, notes, and snippets.

@badgeek
Last active January 31, 2020 11:38
Show Gist options
  • Save badgeek/0718dbd26fa0671e9bc54fe0d156cde5 to your computer and use it in GitHub Desktop.
Save badgeek/0718dbd26fa0671e9bc54fe0d156cde5 to your computer and use it in GitHub Desktop.

Revisions

  1. badgeek revised this gist Jan 31, 2020. No changes.
  2. badgeek revised this gist Jan 31, 2020. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -38,8 +38,20 @@ const BasicMachine = Machine({
    },
    error : {
    states : {
    loading_fail : {},
    creating_fail : {}
    loading_fail : {
    on : {
    RETRY : {
    target : "#copying.loading"
    }
    }
    },
    creating_fail : {
    on : {
    RETRY : {
    target : "#copying.creating"
    }
    }
    }
    }
    },
    inactive: {
  3. badgeek created this gist Jan 31, 2020.
    65 changes: 65 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    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.error.loading_fail",
    actions: "debug"
    }
    }
    },
    creating: {
    invoke: {
    id: "createschedule",
    src: "createscheduleservice",
    onDone: {
    target: "#basicmachine.inactive",
    actions: "debug"
    },
    onError: {
    target: "#basicmachine.error.creating_fail",
    actions: "debug"
    }
    }
    }},
    },
    error : {
    states : {
    loading_fail : {},
    creating_fail : {}
    }
    },
    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")
    }
    }
    }
    }
    });