Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 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 singlePage = 5;
  13.  
  14. const selectedMachine = Machine({
  15. id: "selected",
  16. initial: "empty",
  17. context: {
  18. cache: false
  19. },
  20. states: {
  21. empty: {
  22. on: {
  23. SELECTION_ADDED: "some"
  24. }
  25. },
  26. some: {
  27. on: {
  28. SELECTION_ADDED: [{
  29. target: "fetching",
  30. cond: "pageExistsInCache"
  31. },
  32. {
  33. target: "some"
  34. }],
  35. PAGE_REQUESTED: [{
  36. target: "fetching",
  37. cond: "pageExistsInCache"
  38. },
  39. {
  40. target: "some"
  41. }]
  42. }
  43. },
  44. fetching: {
  45. invoke: {
  46. src: () => new Promise(res => setTimeout(res, 500)),
  47. onDone: {
  48. target: "some",
  49. actions: "addToCache"
  50. }
  51. }
  52. }
  53. }
  54. }, {
  55. actions: {
  56. addToCache: assign({
  57. cache: true
  58. })
  59. },
  60. guards: {
  61. pageExistsInCache: (ctx) => ctx.cache
  62. }
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement