Created
          October 8, 2020 12:12 
        
      - 
      
 - 
        
Save NitsanBaleli/ee09ce5bba95a86a6480d4a196a48562 to your computer and use it in GitHub Desktop.  
    Generated by XState Viz: https://xstate.js.org/viz
  
        
  
    
      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 characters
    
  
  
    
  | // Available variables: | |
| // - Machine | |
| // - interpret | |
| // - assign | |
| // - send | |
| // - sendParent | |
| // - spawn | |
| // - raise | |
| // - actions | |
| // - XState (all XState exports) | |
| const fetchMachine = Machine({ | |
| id: 'fetch', | |
| initial: 'idle', | |
| context: { | |
| networkQuality: '', | |
| neverShowWarning: false, | |
| warningTimstamp: undefined | |
| }, | |
| states: { | |
| idle: { | |
| }, | |
| warning: { | |
| }, | |
| idleNoWarning: { | |
| on: { | |
| REPORT_NETWORK_QUALITY: { | |
| } | |
| } | |
| } | |
| }, | |
| on: { | |
| REPORT_NETWORK_QUALITY: [ | |
| { | |
| target: "warning", | |
| cond: (ctx, event) => { return event.payload === 'bad' || event.payload === 'worse'}, | |
| actions: assign({ | |
| networkQuality: (ctx, event) => event.payload, | |
| warningTimstamp: () => { | |
| const x = new Date(); | |
| return x.getTime(); | |
| } | |
| }) | |
| }, | |
| { | |
| target: "idle", | |
| cond: function(ctx, event) { | |
| const x = new Date(); | |
| const twoSecondsPassed = (x.getTime() - ctx.warningTimstamp) >= 2000; | |
| return twoSecondsPassed && event.payload !== 'bad' && event.payload !== 'worse' | |
| }, | |
| actions: assign({ | |
| networkQuality: (ctx, event) => event.payload | |
| }) | |
| } | |
| , { | |
| actions: assign({ | |
| networkQuality: (ctx, event) => event.payload | |
| }) | |
| } | |
| ], | |
| DISMISS_NETWORK_QUALITY_WARNING: 'idleNoWarning' | |
| } | |
| }); | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment