SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Available variables:
  2.   // - Machine
  3.   // - interpret
  4.   // - assign
  5.   // - send
  6.   // - sendParent
  7.   // - spawn
  8.   // - raise
  9.   // - actions
  10.   // - XState (all XState exports)
  11.  
  12.   const fileSelectState = {
  13.     initial: 'noFileSelected',
  14.     states: {
  15.       noFileSelected: {
  16.         on: {
  17.           SELECT_FILE: 'fileSelected',
  18.         }
  19.       },
  20.       fileSelected: {
  21.         initial: 'idle',
  22.         states: {
  23.           idle: {
  24.             on: {
  25.               'SEND': 'sending',
  26.             },
  27.           },
  28.           // disable editor and send btn
  29.           sending: {
  30.             on: {
  31.               'SEND_SUCCESS': 'idle',
  32.               // Sow error message
  33.               'SEND_ERROR': 'idle',
  34.             },
  35.           },
  36.         },
  37.       },
  38.     },
  39.   };
  40.  
  41.   const fetchMachine = Machine({
  42.     id: 'templateSelector',
  43.     initial: 'samples',
  44.     states: {
  45.       samples: {
  46.         context: {
  47.           sampleId: ''
  48.         },
  49.         ...fileSelectState
  50.       },
  51.       files: {
  52.         initial: 'idle',
  53.         context: {
  54.           specifiedFolderId: '',
  55.           loadedFolderId: '',
  56.           selectedFileId: '',
  57.         },
  58.         states: {
  59.           idle: {
  60.             on: {
  61.               FETCH_FOLDER: 'folderLoading'
  62.             }
  63.           },
  64.           folderLoading: {
  65.             on: {
  66.               RESOLVE: 'folderSuccess',
  67.               REJECT: 'folderFailure'
  68.             }
  69.           },
  70.           folderSuccess: {
  71.             // Select and send files
  72.             ...fileSelectState,
  73.             on: {
  74.               FETCH_FOLDER: 'folderLoading',
  75.             },
  76.           },
  77.           folderFailure: {
  78.             on: {
  79.               FETCH_FOLDER: 'folderLoading',
  80.             },
  81.           },
  82.         },
  83.       }
  84.     }
  85.   });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top