Skip to content

Instantly share code, notes, and snippets.

@saadshahd
Last active November 4, 2020 12:10
Show Gist options
  • Save saadshahd/30e6c3d66ea00c23ffdeead749a8dafe to your computer and use it in GitHub Desktop.
Save saadshahd/30e6c3d66ea00c23ffdeead749a8dafe to your computer and use it in GitHub Desktop.

Revisions

  1. saadshahd revised this gist Nov 4, 2020. 1 changed file with 77 additions and 5 deletions.
    82 changes: 77 additions & 5 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,10 @@ const stateMachine = Machine({
    states: {
    info: {
    initial: "Created",
    on: {
    FORFEITED: '.Forfeited',
    CANCELLED: '.Cancelled',
    },
    states: {
    Created: {
    on: {
    @@ -31,14 +35,19 @@ const stateMachine = Machine({
    INFO_READY_FOR_COLLECTION: "ReadyForCollection"
    }
    },
    ReadyForCollection: {}
    ReadyForCollection: {},
    Forfeited: {},
    Cancelled: {}
    }
    },
    collection: {
    initial: "Unassigned",

    initial: "NotStarted",
    on: {
    FORFEITED: '.NotStarted',
    CANCELLED: '.NotStarted',
    },
    states: {
    Unassigned: {
    NotStarted: {
    on: {
    COLLECTION_START: "InProgress",
    COLLECTION_COMPLETE: "Complete"
    @@ -60,7 +69,10 @@ const stateMachine = Machine({
    },
    ops: {
    initial: "Unassigned",

    on: {
    FORFEITED: '.Unassigned',
    CANCELLED: '.Unassigned',
    },
    states: {
    Unassigned: {
    on: {
    @@ -77,6 +89,10 @@ const stateMachine = Machine({
    },
    video: {
    initial: "Untracked",
    on: {
    FORFEITED: '.Untracked',
    CANCELLED: '.Untracked',
    },
    states: {
    Untracked: {
    initial: "idle",
    @@ -121,6 +137,62 @@ const stateMachine = Machine({

    Found: {}
    }
    },
    sbd: {
    initial: 'NotImported',
    on: {
    FORFEITED: '.NotImported',
    CANCELLED: '.NotImported',
    },
    states: {
    NotImported: {
    on: {
    SBD_IMPORT_START: 'Processing',
    SBD_IMPORT_SUCCESS: 'Available',
    SBD_IMPORT_FAILED: 'Failed',
    },
    },

    Processing: {
    on: {
    SBD_IMPORT_SUCCESS: 'Available',
    SBD_IMPORT_FAILED: 'Failed',
    },
    },

    Failed: {
    on: {
    SBD_IMPORT_START: 'Processing',
    },
    },

    Available: {
    on: {
    SBD_IMPORT_START: 'Updating',
    SBD_IMPORT_FAILED: 'Failed',
    },
    },

    Updating: {
    on: {
    SBD_IMPORT_SUCCESS: 'Updated',
    SBD_IMPORT_FAILED: 'FailedUpdate',
    },
    },

    Updated: {
    on: {
    SBD_IMPORT_START: 'Updating',
    SBD_IMPORT_FAILED: 'FailedUpdate',
    },
    },

    FailedUpdate: {
    on: {
    SBD_IMPORT_START: 'Updating',
    },
    },
    },
    }
    }
    });
  2. saadshahd created this gist Sep 19, 2020.
    126 changes: 126 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@
    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const stateMachine = Machine({
    id: "status",
    type: "parallel",
    states: {
    info: {
    initial: "Created",
    states: {
    Created: {
    on: {
    INFO_OFFICIALLY_SCHEDULED: {
    target: "OfficiallyScheduled",
    actions: ["scheduleVideo"]
    },
    INFO_READY_FOR_COLLECTION: "ReadyForCollection"
    }
    },

    OfficiallyScheduled: {
    on: {
    INFO_READY_FOR_COLLECTION: "ReadyForCollection"
    }
    },
    ReadyForCollection: {}
    }
    },
    collection: {
    initial: "Unassigned",

    states: {
    Unassigned: {
    on: {
    COLLECTION_START: "InProgress",
    COLLECTION_COMPLETE: "Complete"
    }
    },

    InProgress: {
    on: {
    COLLECTION_COMPLETE: "Complete"
    }
    },

    Complete: {
    on: {
    COLLECTION_INCOMPLETE: "InProgress"
    }
    }
    }
    },
    ops: {
    initial: "Unassigned",

    states: {
    Unassigned: {
    on: {
    OPS_ASSIGN: "Assigned"
    }
    },

    Assigned: {
    on: {
    OPS_UNASSIGN: "Unassigned"
    }
    }
    }
    },
    video: {
    initial: "Untracked",
    states: {
    Untracked: {
    initial: "idle",

    on: {
    VIDEO_SCHEDULED: "Scheduled",
    VIDEO_FOUND: "Found",
    VIDEO_NOT_FOUND: "NotFound"
    },

    states: {
    idle: {
    on: {
    VIDEO_SCHEDULE: "scheduling"
    }
    },
    scheduling: {
    invoke: {
    id: "scheduleVideo",
    src: "scheduleVideo",
    onDone: {
    target: "#VideoScheduled"
    }
    }
    }
    }
    },

    Scheduled: {
    id: "VideoScheduled",
    on: {
    VIDEO_FOUND: "Found",
    VIDEO_NOT_FOUND: "NotFound"
    }
    },

    NotFound: {
    on: {
    VIDEO_FOUND: "Found"
    }
    },

    Found: {}
    }
    }
    }
    });