Advertisement
Guest User

Untitled

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