Skip to content

Instantly share code, notes, and snippets.

@pke
Last active June 8, 2021 17:03

Revisions

  1. pke revised this gist Jun 8, 2021. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,9 @@
    initial: 'scanning',
    context: {
    qrcode: "",
    screen: "map"
    sourceScreen: "fav", // rdonly
    targetScreen: "", // write
    targetScreenParams: {} // write
    },
    states: {
    scanning: {
    @@ -36,7 +38,7 @@
    }
    },
    showFullScreen: {
    finished: true
    type: 'final'
    },
    saveFavorite: {
    on: {
  2. pke created this gist Jun 8, 2021.
    53 changes: 53 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'scanning',
    context: {
    qrcode: "",
    screen: "map"
    },
    states: {
    scanning: {
    on: {
    SCANNED: "validate",
    }
    },
    validate: {
    on: {
    URL: "checkFavorite",
    OTHER: "error"
    },
    },
    checkFavorite: {
    on: {
    IS_FAV: "showFullScreen",
    NOT_FAV: "saveFavorite",
    }
    },
    showFullScreen: {
    finished: true
    },
    saveFavorite: {
    on: {
    SAVED: "showFullScreen",
    }
    },
    error: {
    on: {
    RETRY: "scanning",
    }
    }
    }
    });