Skip to content

Instantly share code, notes, and snippets.

@llldc21
Last active January 17, 2020 20:09
Show Gist options
  • Select an option

  • Save llldc21/564652e4060588a6b608865475940007 to your computer and use it in GitHub Desktop.

Select an option

Save llldc21/564652e4060588a6b608865475940007 to your computer and use it in GitHub Desktop.

Revisions

  1. llldc21 revised this gist Jan 17, 2020. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,19 @@ const fetchMachine = Machine({
    },
    states: {
    draft: {
    on: {
    READY: 'ready',
    onEntry: ['test'],
    after: {
    run: [
    { target: 'ok' },
    { target: 'fail' }
    ]
    }
    },
    ready: {
    ok: {
    type: 'final'
    },
    fail: {
    type: 'final'
    }
    }
    });
  2. llldc21 revised this gist Jan 17, 2020. 1 changed file with 1 addition and 46 deletions.
    47 changes: 1 addition & 46 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    const fetchMachine = Machine({
    id: 'e-proposal',
    id: 'fetch',
    initial: 'draft',
    context: {
    state: 'draft'
    @@ -8,55 +8,10 @@ const fetchMachine = Machine({
    draft: {
    on: {
    READY: 'ready',
    DELETED: 'deleted'
    }
    },
    ready: {
    on: {
    QUEUE: 'queue',
    INBOX: 'inbox'
    }
    },
    queue: {
    on: {
    SEND: 'waiting'
    }
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    SEND: 'waiting',
    DRAFT: 'draft'
    }
    },
    waiting: {
    on: {
    CANCELED: 'canceled',
    ACCEPTED: 'accepted',
    REFUSED: 'refused'
    }
    },
    canceled: {
    on: {
    DRAFT: 'draft',
    },
    type: 'final'
    },
    accepted: {
    on: {
    WAITING: 'waiting',
    CANCELED: "canceled",
    },
    type: 'final'
    },
    refused: {
    on: {
    DRAFT: 'draft'
    },
    type: 'final'
    },
    deleted: {
    type: 'final'
    }
    }
    });
  3. llldc21 revised this gist Jan 17, 2020. 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
    @@ -1,5 +1,5 @@
    const fetchMachine = Machine({
    id: 'fetch',
    id: 'e-proposal',
    initial: 'draft',
    context: {
    state: 'draft'
  4. llldc21 revised this gist Jan 17, 2020. 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 fetchMachine = Machine({
    id: 'fetch',
    initial: 'draft',
    context: {
    state: 'draft'
    },
    states: {
    draft: {
    on: {
  5. llldc21 revised this gist Jan 17, 2020. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,6 @@
    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'draft',
    context: {
    retries: 0
    },
    states: {
    draft: {
    on: {
  6. llldc21 revised this gist Jan 17, 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
    @@ -19,13 +19,13 @@ const fetchMachine = Machine({
    },
    queue: {
    on: {
    WAITING: 'waiting'
    SEND: 'waiting'
    }
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    WAITING: 'waiting',
    SEND: 'waiting',
    DRAFT: 'draft'
    }
    },
  7. llldc21 revised this gist Jan 17, 2020. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -57,9 +57,6 @@ const fetchMachine = Machine({
    },
    deleted: {
    type: 'final'
    },
    final: {
    type: 'final'
    }
    }
    });
  8. llldc21 revised this gist Jan 17, 2020. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -39,8 +39,8 @@ const fetchMachine = Machine({
    canceled: {
    on: {
    DRAFT: 'draft',
    FINAL: 'final'
    }
    },
    type: 'final'
    },
    accepted: {
    on: {
    @@ -50,8 +50,10 @@ const fetchMachine = Machine({
    type: 'final'
    },
    refused: {
    DRAFT: 'draft',
    FINAL: 'final'
    on: {
    DRAFT: 'draft'
    },
    type: 'final'
    },
    deleted: {
    type: 'final'
  9. llldc21 revised this gist Jan 17, 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
    @@ -46,8 +46,8 @@ const fetchMachine = Machine({
    on: {
    WAITING: 'waiting',
    CANCELED: "canceled",
    FINAL: 'final'
    }
    },
    type: 'final'
    },
    refused: {
    DRAFT: 'draft',
  10. llldc21 revised this gist Jan 17, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,8 @@ const fetchMachine = Machine({
    accepted: {
    on: {
    WAITING: 'waiting',
    CANCELED: "canceled"
    CANCELED: "canceled",
    FINAL: 'final'
    }
    },
    refused: {
  11. llldc21 revised this gist Jan 17, 2020. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -18,11 +18,14 @@ const fetchMachine = Machine({
    }
    },
    queue: {
    type: 'waiting'
    on: {
    WAITING: 'waiting'
    }
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    WAITING: 'waiting',
    DRAFT: 'draft'
    }
    },
  12. llldc21 revised this gist Jan 17, 2020. 1 changed file with 17 additions and 12 deletions.
    29 changes: 17 additions & 12 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -15,16 +15,16 @@ const fetchMachine = Machine({
    on: {
    QUEUE: 'queue',
    INBOX: 'inbox'
    },
    queue: {
    type: 'waiting'
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    DRAFT: 'draft'
    }
    },
    }
    },
    queue: {
    type: 'waiting'
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    DRAFT: 'draft'
    }
    },
    waiting: {
    on: {
    @@ -35,7 +35,8 @@ const fetchMachine = Machine({
    },
    canceled: {
    on: {
    DRAFT: 'draft'
    DRAFT: 'draft',
    FINAL: 'final'
    }
    },
    accepted: {
    @@ -45,10 +46,14 @@ const fetchMachine = Machine({
    }
    },
    refused: {
    DRAFT: 'draft'
    DRAFT: 'draft',
    FINAL: 'final'
    },
    deleted: {
    type: 'final'
    },
    final: {
    type: 'final'
    }
    }
    });
  13. llldc21 revised this gist Jan 17, 2020. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -15,16 +15,16 @@ const fetchMachine = Machine({
    on: {
    QUEUE: 'queue',
    INBOX: 'inbox'
    }
    },
    queue: {
    type: 'waiting'
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    DRAFT: 'draft'
    }
    },
    queue: {
    type: 'waiting'
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    DRAFT: 'draft'
    }
    },
    },
    waiting: {
    on: {
    @@ -51,4 +51,4 @@ const fetchMachine = Machine({
    type: 'final'
    }
    }
    });
    });
  14. llldc21 revised this gist Jan 17, 2020. 1 changed file with 47 additions and 20 deletions.
    67 changes: 47 additions & 20 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,54 @@
    const fetchMachine = Machine({
    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'draft',
    context: {
    retries: 0
    retries: 0
    },
    states: {
    draft: {
    on: {
    READY: 'ready'
    draft: {
    on: {
    READY: 'ready',
    DELETED: 'deleted'
    }
    },
    ready: {
    on: {
    QUEUE: 'queue',
    INBOX: 'inbox'
    }
    },
    queue: {
    type: 'waiting'
    },
    inbox: {
    on: {
    CANCELED: 'canceled',
    DRAFT: 'draft'
    }
    },
    waiting: {
    on: {
    CANCELED: 'canceled',
    ACCEPTED: 'accepted',
    REFUSED: 'refused'
    }
    },
    canceled: {
    on: {
    DRAFT: 'draft'
    }
    },
    accepted: {
    on: {
    WAITING: 'waiting',
    CANCELED: "canceled"
    }
    },
    refused: {
    DRAFT: 'draft'
    },
    deleted: {
    type: 'final'
    }
    },
    ready: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    type: 'final'
    }
    }
    });

    });
  15. llldc21 revised this gist Jan 17, 2020. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -20,14 +20,7 @@
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    type: 'final'
    }
    }
    });
  16. llldc21 revised this gist Jan 17, 2020. No changes.
  17. llldc21 created this gist Jan 17, 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: 'draft',
    context: {
    retries: 0
    },
    states: {
    draft: {
    on: {
    READY: 'ready'
    }
    },
    ready: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });