Skip to content

Instantly share code, notes, and snippets.

@JayBee007
Last active September 11, 2021 06:54
Show Gist options
  • Select an option

  • Save JayBee007/422e0625c0d8b0a5cda75581dda7b3d3 to your computer and use it in GitHub Desktop.

Select an option

Save JayBee007/422e0625c0d8b0a5cda75581dda7b3d3 to your computer and use it in GitHub Desktop.

Revisions

  1. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 12 additions and 5 deletions.
    17 changes: 12 additions & 5 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -21,13 +21,20 @@ const timerMachine = Machine({
    },
    },
    on: {
    TICK: {
    entry: () => console.log('tick')
    }
    },
    TICK: {
    actions: assign({
    secondsLeft: (ctx) => ctx.secondsLeft - 1
    })
    }
    },
    states: {
    round: {

    on: {
    '': {
    target: 'interval',
    cond: (ctx) => ctx.secondsLeft < 0
    }
    }
    },
    interval: {}
    },
  2. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -20,13 +20,14 @@ const timerMachine = Machine({
    return () => clearInterval(timerId)
    },
    },
    states: {
    round: {
    on: {
    on: {
    TICK: {
    entry: () => console.log('tick')
    }
    }
    },
    states: {
    round: {

    },
    interval: {}
    },
  3. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,11 @@ const timerMachine = Machine({
    },
    states: {
    round: {

    on: {
    TICK: {
    entry: () => console.log('tick')
    }
    }
    },
    interval: {}
    },
  4. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,19 @@ const timerMachine = Machine({
    },
    running: {
    initial: 'round',
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    cb('TICK')
    }, 1000)

    return () => clearInterval(timerId)
    },
    },
    states: {
    round: {},
    round: {

    },
    interval: {}
    },
    on: {
  5. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,11 @@ const timerMachine = Machine({
    }
    },
    running: {
    initial: 'round',
    states: {
    round: {},
    interval: {}
    },
    on: {
    PAUSED: {
    target: 'paused'
  6. JayBee007 revised this gist Sep 11, 2021. 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
    @@ -9,7 +9,7 @@ const timerMachine = Machine({
    }
    }
    },
    runnnig: {
    running: {
    on: {
    PAUSED: {
    target: 'paused'
  7. JayBee007 revised this gist Sep 11, 2021. No changes.
  8. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 3 additions and 18 deletions.
    21 changes: 3 additions & 18 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    const timerMachine = Machine({
    id: 'timerMachine',
    initial: 'paused',
    initial: "paused",
    states: {
    paused: {
    on: {
    @@ -9,27 +9,12 @@ const timerMachine = Machine({
    }
    }
    },
    running: {
    intial: 'round',
    states: {
    round: {},
    interval: {}
    },
    runnnig: {
    on: {
    PAUSED: {
    target: 'paused'
    }
    },
    // invoke: {
    // src: () => (cb) => {
    // let timerId = setInterval(() => {
    // cb('TICK')
    // },1000)

    // return () => clearInterval(timerId)
    // },
    // },

    }
    }
    }
    })
  9. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 13 additions and 12 deletions.
    25 changes: 13 additions & 12 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -11,24 +11,25 @@ const timerMachine = Machine({
    },
    running: {
    intial: 'round',
    states: {
    round: {},
    interval: {}
    },
    on: {
    PAUSED: {
    target: 'paused'
    }
    },
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    cb('TICK')
    },1000)
    // invoke: {
    // src: () => (cb) => {
    // let timerId = setInterval(() => {
    // cb('TICK')
    // },1000)

    return () => clearInterval(timerId)
    },
    },
    states: {
    round: {},
    interval: {}
    }
    // return () => clearInterval(timerId)
    // },
    // },

    }
    }
    })
  10. JayBee007 revised this gist Sep 11, 2021. No changes.
  11. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,11 @@ const timerMachine = Machine({
    initial: 'paused',
    states: {
    paused: {

    on: {
    START: {
    target: 'running'
    }
    }
    },
    running: {
    intial: 'round',
  12. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,11 @@ const timerMachine = Machine({
    },
    running: {
    intial: 'round',
    on: {
    PAUSED: {
    target: 'paused'
    }
    },
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
  13. JayBee007 revised this gist Sep 11, 2021. 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
    @@ -7,6 +7,15 @@ const timerMachine = Machine({
    },
    running: {
    intial: 'round',
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    cb('TICK')
    },1000)

    return () => clearInterval(timerId)
    },
    },
    states: {
    round: {},
    interval: {}
  14. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 4 additions and 38 deletions.
    42 changes: 4 additions & 38 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,15 @@
    const timerMachine = Machine({
    id: 'timerMachine',
    initial: 'paused',
    context: {
    secondsLeft: 5
    },
    states: {
    paused: {
    on: {
    START: {
    target: 'running'
    }
    }

    },
    running: {
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    console.log('setInterval')
    cb('TICK')
    }, 1000)
    return () => clearInterval(timerId)
    },
    },
    on: {
    PAUSED: {
    target: 'paused'
    },
    TICK: {
    entry: () => console.log('tick')
    },
    },
    initial: 'round',
    intial: 'round',
    states: {
    round: {
    on: {
    '':{
    target: 'interval',
    cond: (ctx) => ctx.secondsLeft < 0
    }
    },

    },
    interval: {

    }
    round: {},
    interval: {}
    }
    }
    }
  15. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -16,22 +16,24 @@ const timerMachine = Machine({
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    console.log('setInterval')
    cb('TICK')
    }, 1000)
    return () => clearInterval(timerId)
    },
    },
    on: {
    PAUSED: {
    target: 'paused'
    },
    TICK: {
    entry: () => console.log('tick')
    },
    },
    initial: 'round',
    states: {
    round: {
    on: {
    TICK: {
    entry: () => console.log('tick')
    },
    '':{
    target: 'interval',
    cond: (ctx) => ctx.secondsLeft < 0
  16. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -31,12 +31,13 @@ const timerMachine = Machine({
    on: {
    TICK: {
    entry: () => console.log('tick')
    }
    },
    '':{
    },
    '':{
    target: 'interval',
    cond: (ctx) => ctx.secondsLeft < 0
    }
    },

    },
    interval: {

  17. JayBee007 revised this gist Sep 11, 2021. 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
    @@ -24,14 +24,16 @@ const timerMachine = Machine({
    PAUSED: {
    target: 'paused'
    },
    TICK: {
    entry: () => console.log('tick')
    }
    },
    initial: 'round',
    states: {
    round: {
    always:{
    on: {
    TICK: {
    entry: () => console.log('tick')
    }
    },
    '':{
    target: 'interval',
    cond: (ctx) => ctx.secondsLeft < 0
    }
  18. JayBee007 revised this gist Sep 11, 2021. 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
    @@ -24,6 +24,9 @@ const timerMachine = Machine({
    PAUSED: {
    target: 'paused'
    },
    TICK: {
    entry: () => console.log('tick')
    }
    },
    initial: 'round',
    states: {
  19. JayBee007 revised this gist Sep 11, 2021. 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
    @@ -28,7 +28,10 @@ const timerMachine = Machine({
    initial: 'round',
    states: {
    round: {

    always:{
    target: 'interval',
    cond: (ctx) => ctx.secondsLeft < 0
    }
    },
    interval: {

  20. JayBee007 revised this gist Sep 11, 2021. 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
    @@ -23,7 +23,7 @@ const timerMachine = Machine({
    on: {
    PAUSED: {
    target: 'paused'
    }
    },
    },
    initial: 'round',
    states: {
  21. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,13 @@ const timerMachine = Machine({
    }
    },
    running: {
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    cb('TICK')
    }, 1000)
    },
    },
    on: {
    PAUSED: {
    target: 'paused'
  22. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,11 @@ const timerMachine = Machine({
    }
    },
    running: {
    on: {
    PAUSED: {
    target: 'paused'
    }
    },
    initial: 'round',
    states: {
    round: {
  23. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,15 @@ const timerMachine = Machine({
    }
    },
    running: {

    initial: 'round',
    states: {
    round: {

    },
    interval: {

    }
    }
    }
    }
    })
  24. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 1 addition and 27 deletions.
    28 changes: 1 addition & 27 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -13,33 +13,7 @@ const timerMachine = Machine({
    }
    },
    running: {
    on: {
    PAUSED: {
    target: 'paused'
    },
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    cb('TICK')
    }, 1000)
    }
    },
    initial: 'round',
    states: {
    round: {
    on: {
    TICK: {
    actions: assign({
    secondsLeft: (ctx) => ctx.secondsLeft - 1
    })
    }
    }
    }
    },
    interval: {

    }
    }

    }
    }
    })
  25. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -27,11 +27,13 @@ const timerMachine = Machine({
    initial: 'round',
    states: {
    round: {
    TICK: {
    on: {
    TICK: {
    actions: assign({
    secondsLeft: (ctx) => ctx.secondsLeft - 1
    })
    }
    }
    }
    },
    interval: {
  26. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,10 @@ const timerMachine = Machine({
    }
    },
    running: {
    on: {
    PAUSED: {
    target: 'paused'
    },
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    @@ -23,10 +27,6 @@ const timerMachine = Machine({
    initial: 'round',
    states: {
    round: {
    on: {
    PAUSED: {
    target: 'paused'
    },
    TICK: {
    actions: assign({
    secondsLeft: (ctx) => ctx.secondsLeft - 1
  27. JayBee007 revised this gist Sep 11, 2021. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    const timerMachine = Machine({
    id: 'timerMachine',
    initial: 'paused',
    context: {
    secondsLeft: 5
    },
    states: {
    paused: {
    on: {
    @@ -20,7 +23,16 @@ const timerMachine = Machine({
    initial: 'round',
    states: {
    round: {

    on: {
    PAUSED: {
    target: 'paused'
    },
    TICK: {
    actions: assign({
    secondsLeft: (ctx) => ctx.secondsLeft - 1
    })
    }
    }
    },
    interval: {

  28. JayBee007 created this gist Sep 11, 2021.
    31 changes: 31 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    const timerMachine = Machine({
    id: 'timerMachine',
    initial: 'paused',
    states: {
    paused: {
    on: {
    START: {
    target: 'running'
    }
    }
    },
    running: {
    invoke: {
    src: () => (cb) => {
    let timerId = setInterval(() => {
    cb('TICK')
    }, 1000)
    }
    },
    initial: 'round',
    states: {
    round: {

    },
    interval: {

    }
    }
    }
    }
    })