Last active
          June 29, 2021 20:26 
        
      - 
      
- 
        Save farskid/8c44f3bda8e809bb5c4e76d5cbad8393 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
    
  
  
    
  | Machine({ | |
| id: 'a', | |
| initial: 'checking_url', | |
| context: {gistID: null, gistRawContent: null}, | |
| states: { | |
| checking_url: { | |
| entry: 'parseQueries', | |
| always: [ | |
| { target: 'with_gist', cond: 'isGistIDAvailable' }, | |
| { target: 'no_gist' } | |
| ] | |
| }, | |
| with_gist: { | |
| initial: 'loading_content', | |
| states: { | |
| loading_content: { | |
| invoke: { | |
| src: 'loadGistContent', | |
| onDone: { | |
| target: 'gist_loaded', | |
| actions: [(_, e) => e.data] | |
| }, | |
| onError: { | |
| target: 'gist_error', | |
| actions: ['showError'] | |
| } | |
| } | |
| }, | |
| gist_loaded: { | |
| type: 'final' | |
| }, | |
| gist_error: { | |
| type: 'final' | |
| } | |
| } | |
| }, | |
| no_gist: { | |
| type: 'final' | |
| } | |
| } | |
| }, { | |
| actions: { | |
| parseQueries: assign({ | |
| gistID: new URLSearchParams(window.location.search).get('gist') | |
| }) | |
| }, | |
| guards: { | |
| isGistIDAvailable: ctx => !!ctx.gistID | |
| }, | |
| services: { | |
| loadGistContent: ctx => { | |
| return fetch('https://api.github.com/gist/' + ctx.gistID).then(resp => { | |
| if (resp.status === 404) { | |
| return Promise.reject(Error('Gist not found')) | |
| } | |
| }) | |
| } | |
| } | |
| }) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment