SHARE
TWEET

Untitled

a guest Oct 21st, 2019 86 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 smartRecommendationsMachineConfig = Machine({
  13.   id: 'recommendations',
  14.   initial: 'loading',
  15.   context: {
  16.     highlighted: null,
  17.     recommendations: [],
  18.   },
  19.   states: {
  20.     loading: {
  21.       invoke: {
  22.         src: () => setTimeout(() => Promise.resolve(), 500),
  23.         onDone: 'loaded',
  24.         onError: 'hasError',
  25.       },
  26.     },
  27.     loaded: {
  28.       entry: ['saveRecommendations', 'setHighlighted'],
  29.       initial: 'ready',
  30.       states: {
  31.         ready: {
  32.           on: {
  33.             OMIT_RECOMMENDATION: {
  34.               target: 'omiting',
  35.               actions: ['findNextHighlighted'],
  36.             },
  37.           },
  38.         },
  39.         omiting: {
  40.           invoke: {
  41.             src: setTimeout(() => Promise.resolve(), 500),
  42.             onDone: '#recommendations.loading',
  43.             onError: 'omitFailed',
  44.           },
  45.         },
  46.         omitFailed: {
  47.           on: {
  48.             RETRY_OMIT: 'omiting',
  49.           },
  50.         },
  51.       },
  52.     },
  53.     hasError: {
  54.       RETRY_LOAD_RECOMMENDATIONS: 'loading',
  55.     },
  56.   },
  57. })
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
 
Top