Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  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 load = () => new Promise(resolve => {})
  13.  
  14. const fetchMachine = Machine({
  15. id: 'fetch',
  16. initial: 'idle',
  17. context: {
  18. retries: 0
  19. },
  20. states: {
  21. idle: {
  22. on: {
  23. FETCH: 'loading'
  24. }
  25. },
  26. loading: {
  27. invoke: {
  28. src: load,
  29. onDone: 'success',
  30. onError: 'failure',
  31. },
  32. },
  33. success: {
  34. type: 'final'
  35. },
  36. failure: {
  37. on: {
  38. RETRY: {
  39. target: 'loading',
  40. actions: assign({
  41. retries: (context, event) => context.retries + 1
  42. })
  43. }
  44. }
  45. }
  46. }
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement