Skip to content

Instantly share code, notes, and snippets.

@22mahmoud
Last active April 12, 2020 14:15
Show Gist options
  • Save 22mahmoud/eda387743c93ac8d2d4f65bd9c101036 to your computer and use it in GitHub Desktop.
Save 22mahmoud/eda387743c93ac8d2d4f65bd9c101036 to your computer and use it in GitHub Desktop.

Revisions

  1. 22mahmoud revised this gist Apr 12, 2020. 1 changed file with 5 additions and 24 deletions.
    29 changes: 5 additions & 24 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,15 @@
    const playerMachine = Machine({
    id: 'player',
    initial: 'idle',
    context: {
    retries: 0
    },
    initial: 'loading',
    states: {
    idle: {
    on: {
    FETCH: 'success'
    }
    },

    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'

    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }


    }
    });

  2. 22mahmoud revised this gist Apr 12, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    const fetchMachine = Machine({
    id: 'fetch',
    const playerMachine = Machine({
    id: 'player',
    initial: 'idle',
    context: {
    retries: 0
  3. 22mahmoud created this gist Apr 12, 2020.
    34 changes: 34 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'idle',
    context: {
    retries: 0
    },
    states: {
    idle: {
    on: {
    FETCH: 'success'
    }
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });