Last active
          February 25, 2021 04:18 
        
      - 
      
 - 
        
Save xralphack/23a12a3034ad319138febe0e9eb23f19 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 17 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,6 @@ const yardianStateMachine = Machine({ context: { retries: 0, deviceState: null, }, states: { fetchingDeviceState: { @@ -60,29 +59,30 @@ const yardianStateMachine = Machine({ } }, offline: { }, watering: { after: { 500: { target: 'parsingDeviceState' } } }, firmwareUpdating: { }, idle: { }, failure: { on: { '': { target: "fatal", cond: (context) => context.retries >= 3 } }, // after: { // 1000: { // target: 'fetchingDeviceState', // } // } }, fatal: { on: { @@ -104,8 +104,6 @@ const yardianStateMachine = Machine({ guards: { 'isOffline': ctx => ctx.deviceState && ctx.deviceState.offline, 'isWatering': ctx => { return ctx.deviceState && ctx.deviceState.isWatering }, 'isFirmwareUpdating': ctx => ctx.deviceState && ctx.deviceState.isFirmwareUpdating  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ const fetchDeviceState = () => Promise.resolve({ 'online': true, 'isWatering': Math.random() > 0.1, 'isFirmwareUpdating': false }) @@ -103,7 +103,11 @@ const yardianStateMachine = Machine({ }, guards: { 'isOffline': ctx => ctx.deviceState && ctx.deviceState.offline, 'isWatering': ctx => { console.log('check isWatering') return ctx.deviceState && ctx.deviceState.isWatering }, 'isFirmwareUpdating': ctx => ctx.deviceState && ctx.deviceState.isFirmwareUpdating } });  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 25 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ const yardianStateMachine = Machine({ id: 'fetchDeviceState', src: fetchDeviceState, onDone: { target: 'parsingDeviceState', actions: [ 'resetRetries', 'setDeviceState', @@ -38,12 +38,25 @@ const yardianStateMachine = Machine({ // } // } }, parsingDeviceState: { on: { '': [ { target: 'offline', cond: 'isOffline' }, { target: 'watering', cond: 'isWatering' }, { target: 'firmwareUpdating', cond: 'isFirmwareUpdating' }, { target: 'idle', } ] } }, offline: { @@ -52,24 +65,12 @@ const yardianStateMachine = Machine({ watering: { }, firmwareUpdating: { }, idle: { }, failure: { on: { '': {  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,12 @@ const yardianStateMachine = Machine({ // } }, parseDeviceState: { on: { '': { target: 'offline', cond: 'isOffline' } } }, offline: { @@ -93,11 +98,7 @@ const yardianStateMachine = Machine({ 'resetRetries': assign({ retries: 0 }), 'setDeviceState': assign({ deviceState: (_, event) => { console.log(event.data) return event.data }}) }, guards: { 'isOffline': ctx => ctx.deviceState && ctx.deviceState.offline,  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 26 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,10 +19,10 @@ const yardianStateMachine = Machine({ id: 'fetchDeviceState', src: fetchDeviceState, onDone: { target: 'parseDeviceState', actions: [ 'resetRetries', 'setDeviceState', ] }, onError: { @@ -38,35 +38,33 @@ const yardianStateMachine = Machine({ // } // } }, parseDeviceState: { }, offline: { }, watering: { }, // { // target: "ready.watering", // cond: 'isWatering' // }, { // target: "ready.firmwareUpdating", // cond: "isFirmwareUpdating" // }, { // target: "ready.idle" // } // states: { // firmwareUpdating: { // }, // idle: { // }, // } failure: { on: { '': {  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 15 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ const fetchDeviceState = () => Promise.resolve({ 'online': true, 'isWatering': Math.random() > 0.5, 'isFirmwareUpdating': false }) const yardianStateMachine = Machine({ @@ -9,6 +10,7 @@ const yardianStateMachine = Machine({ context: { retries: 0, deviceState: null, interval: 500, }, states: { fetchingDeviceState: { @@ -20,7 +22,8 @@ const yardianStateMachine = Machine({ target: 'ready', actions: [ 'setDeviceState', // 'resetRetries', ] }, onError: { target: 'failure' @@ -54,7 +57,7 @@ const yardianStateMachine = Machine({ offline: { }, watering: { }, firmwareUpdating: { @@ -90,13 +93,18 @@ const yardianStateMachine = Machine({ actions: { 'incrementRetries': assign({ retries: context => context.retries + 1 }), 'resetRetries': assign({ retries: 0 }), 'setDeviceState': assign({ deviceState: (_, event) => { console.log(event.data) return event.data } }) }, guards: { 'isOffline': ctx => ctx.deviceState && ctx.deviceState.offline, 'isWatering': ctx => ctx.deviceState && ctx.deviceState.isWatering, 'isFirmwareUpdating': ctx => ctx.deviceState && ctx.deviceState.isFirmwareUpdating } }); 
 - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,6 @@ const yardianStateMachine = Machine({ }, states: { offline: { }, watering: {  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 21 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,11 +36,29 @@ const yardianStateMachine = Machine({ // } }, ready: { on: { '': [{ target: "ready.offline", cond: "isOffline", }, { target: "ready.watering", cond: 'isWatering' }, { target: "ready.firmwareUpdating", cond: "isFirmwareUpdating" }, { target: "ready.idle" }] }, states: { offline: { }, watering: { }, firmwareUpdating: { }, idle: {  - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 12 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,8 @@ const yardianStateMachine = Machine({ onDone: { target: 'ready', actions: [ 'setDeviceState', 'resetRetries', ] }, onError: { target: 'failure' @@ -35,12 +36,15 @@ const yardianStateMachine = Machine({ // } }, ready: { actions: ['parseDeviceState'], initial: 'watering', states: { watering: { cond: 'isWatering' }, idle: { }, } }, failure: { @@ -69,12 +73,13 @@ const yardianStateMachine = Machine({ actions: { 'incrementRetries': assign({ retries: context => context.retries + 1 }), 'resetRetries': assign({ retries: 0 }), 'setDeviceState': assign({ deviceState: (_, event) => event.data }), 'parseDeviceState': (context, event) => { // console.log(event.data); } }, guards: { 'isWatering': ctx => ctx.deviceState && ctx.deviceState.isWatering } }); 
 - 
        
xralphack revised this gist
Feb 25, 2021 . 1 changed file with 14 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,14 @@ const fetchDeviceState = () => Promise.resolve({ 'online': true, 'isWatering': Math.random() > 0.5 }) const yardianStateMachine = Machine({ id: 'yardian-state-machine', initial: 'fetchingDeviceState', context: { retries: 0, deviceState: null, }, states: { fetchingDeviceState: { @@ -14,7 +17,9 @@ const yardianStateMachine = Machine({ id: 'fetchDeviceState', src: fetchDeviceState, onDone: { target: 'ready', actions: [ 'resetRetries', 'onFetchDeviceStateSuccess'] }, onError: { target: 'failure' @@ -29,8 +34,9 @@ const yardianStateMachine = Machine({ // } // } }, ready: { actions: ['resetRetries', 'parseDeviceState'], initial: 'watering', states: { watering: { @@ -63,6 +69,9 @@ const yardianStateMachine = Machine({ actions: { 'incrementRetries': assign({ retries: context => context.retries + 1 }), 'resetRetries': assign({ retries: 0 }), 'onFetchDeviceStateSuccess': (_, event) => { console.log(event) }, 'parseDeviceState': (context, event) => { console.log(event.data); }  - 
        
xralphack revised this gist
Feb 24, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ const yardianStateMachine = Machine({ // } }, success: { actions: ['resetRetries', 'parseDeviceState'], states: { watering: { @@ -63,7 +63,7 @@ const yardianStateMachine = Machine({ actions: { 'incrementRetries': assign({ retries: context => context.retries + 1 }), 'resetRetries': assign({ retries: 0 }), 'parseDeviceState': (context, event) => { console.log(event.data); } }  - 
        
xralphack revised this gist
Feb 24, 2021 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,12 @@ const yardianStateMachine = Machine({ // } }, success: { entry: ['resetRetries', 'parseDeviceState'], states: { watering: { } } }, failure: { on: { @@ -57,7 +62,10 @@ const yardianStateMachine = Machine({ }, { actions: { 'incrementRetries': assign({ retries: context => context.retries + 1 }), 'resetRetries': assign({ retries: 0 }), parseDeviceState: (context, event) => { console.log(event.data); } } }); 
 - 
        
xralphack revised this gist
Feb 24, 2021 . 1 changed file with 22 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,58 +9,55 @@ const yardianStateMachine = Machine({ }, states: { fetchingDeviceState: { entry: ['incrementRetries'], invoke: { id: 'fetchDeviceState', src: fetchDeviceState, onDone: { target: 'success' }, onError: { target: 'failure' } } // on: { // success: { // target: 'success' // }, // failure: { // target: 'failure' // } // } }, success: { entry: 'resetRetries' }, failure: { on: { '': { target: "fatal", cond: (context) => context.retries >= 3 } }, after: { 1000: { target: 'fetchingDeviceState', } } }, fatal: { on: { RETRY: { target: 'fetchingDeviceState', actions: ['resetRetries'] } } } } }, { actions: { 'incrementRetries': assign({ retries: context => context.retries + 1 }), 'resetRetries': assign({ retries: 0 }) } }); 
 - 
        
xralphack revised this gist
Feb 24, 2021 . 1 changed file with 24 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,18 +9,29 @@ const yardianStateMachine = Machine({ }, states: { fetchingDeviceState: { // invoke: { // id: 'fetchDeviceState', // src: fetchDeviceState, // onDone: { // target: 'success' // }, // onError: { // target: 'failure' // } // } on: { success: { target: 'success' }, failure: { target: 'failure' } } }, success: { entry: () => assign({ retires: 0 }) }, failure: { entry: (context) => { @@ -38,18 +49,18 @@ const yardianStateMachine = Machine({ actions: assign({ retries: context => context.retries+ 1 }) } } }, fatal: { on: { RETRY: { target: 'fetchingDeviceState' } } } } }, { }); 
 - 
        
xralphack revised this gist
Feb 24, 2021 . 1 changed file with 25 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ const fetchDeviceState = () => Math.random() > 0.8 ? Promise.resolve() : Promise.reject() const yardianStateMachine = Machine({ id: 'yardian-state-machine', @@ -12,19 +10,34 @@ const yardianStateMachine = Machine({ states: { fetchingDeviceState: { invoke: { id: 'fetchDeviceState', src: fetchDeviceState, onDone: { target: 'success' }, onError: { target: 'failure' } } }, success: { }, failure: { entry: (context) => { console.log(context) }, on: { '': { target: "fatal", cond: (context) => context.retries > 2 } }, after: { 1000: { target: 'fetchingDeviceState', actions: assign({ retries: context => context.retries+ 1 }) }, // RETRY: { // target: 'fetchingDeviceState', @@ -33,6 +46,9 @@ const yardianStateMachine = Machine({ // }) // } } }, fatal: { } } });  - 
        
xralphack revised this gist
Feb 24, 2021 . 1 changed file with 33 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,39 @@ const fetchDeviceState = () => Promise.resolve({ 'online': true, 'isWatering': Math.random() > 0.5 }) const yardianStateMachine = Machine({ id: 'yardian-state-machine', initial: 'fetchingDeviceState', context: { retries: 0 }, states: { fetchingDeviceState: { invoke: { id: 'fetch' } }, success: { type: 'final' }, failure: { invoke: { }, on: { '': { target: 'fetchingDeviceState' }, // RETRY: { // target: 'fetchingDeviceState', // actions: assign({ // retries: (context, event) => context.retries + 1 // }) // } } } } }); 
 - 
        
xralphack created this gist
Feb 24, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ const yardianStateMachine = Machine({ id: 'yardian-state-machine', initial: 'fetchingDeviceState', context: { retries: 0 }, states: { fetchingDeviceState: { on: { RESOLVE: 'success', REJECT: 'failure' } }, success: { type: 'final' }, failure: { on: { RETRY: { target: 'fetchingDeviceState', actions: assign({ retries: (context, event) => context.retries + 1 }) } } } } });