Skip to content

Instantly share code, notes, and snippets.

@MoonTahoe
Last active November 13, 2019 20:23
Show Gist options
  • Select an option

  • Save MoonTahoe/db7465c3b8ead4c02f13f4ef848e264f to your computer and use it in GitHub Desktop.

Select an option

Save MoonTahoe/db7465c3b8ead4c02f13f4ef848e264f to your computer and use it in GitHub Desktop.

Revisions

  1. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ const lightBulbMachine = Machine({
    entry: [
    () => {
    alert('ya basic')
    window.location.history.refresh();
    window.location.refresh();
    }
    ],
    type: 'final'
  2. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,12 @@ const lightBulbMachine = Machine({
    }
    },
    broken: {
    entry: [
    () => {
    alert('ya basic')
    window.location.history.refresh();
    }
    ],
    type: 'final'
    }
    },
  3. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ const lightBulbMachine = Machine({
    CHANGE_COLOR: {
    actions: [
    assign({
    color: 'green'
    color: (ctx, e) => e.color || 'green'
    })
    ]
    }
  4. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ const lightBulbMachine = Machine({
    id: 'light',
    initial: 'unlit',
    context: {
    color: "#FFFFFF"
    color: "blue"
    },
    states: {
    lit: {
  5. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,14 @@ const lightBulbMachine = Machine({
    broken: {
    type: 'final'
    }
    },
    on: {
    CHANGE_COLOR: {
    actions: [
    assign({
    color: 'green'
    })
    ]
    }
    }
    })
  6. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    const lightBulbMachine = Machine({
    id: 'light',
    initial: 'unlit',
    context: {
    color: "#FFFFFF"
    },
    states: {
    lit: {
    on: {
  7. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 19 additions and 44 deletions.
    63 changes: 19 additions & 44 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,21 @@

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

    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'idle',
    context: {
    retries: 0
    },
    states: {
    idle: {
    on: {
    FETCH: 'loading'
    }
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    const lightBulbMachine = Machine({
    id: 'light',
    initial: 'unlit',
    states: {
    lit: {
    on: {
    TOGGLE:'unlit',
    BREAK:'broken'
    }
    },
    unlit: {
    on: {
    TOGGLE:'lit',
    BREAK:'broken'
    }
    },
    broken: {
    type: 'final'
    }
    });
    }
    })
  8. MoonTahoe revised this gist Nov 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@

    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'success',
    initial: 'idle',
    context: {
    retries: 0
    },
  9. MoonTahoe created this gist Nov 13, 2019.
    46 changes: 46 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

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

    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'success',
    context: {
    retries: 0
    },
    states: {
    idle: {
    on: {
    FETCH: 'loading'
    }
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });