Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. function isMobile(ctx) {
  2. return ctx.screen === 'mobile'
  3. }
  4.  
  5. const updateOrientation = assign({
  6. screen: ctx => ctx.screen === 'desktop' ? 'mobile' : 'desktop'
  7. });
  8.  
  9. const machine = Machine({
  10. initial: 'X',
  11. context: {
  12. screen: 'desktop'
  13. },
  14. states: {
  15. X: {
  16. on: {
  17. NEXT: [
  18. { target: 'AB', cond: isMobile },
  19. { target: 'A' }
  20. ],
  21. REORIENT: { actions: updateOrientation }
  22. }
  23. },
  24. A: {
  25. on: {
  26. BACK: 'X',
  27. NEXT: 'B',
  28. REORIENT: { actions: updateOrientation }
  29. }
  30. },
  31. B: {
  32. on: {
  33. BACK: 'A',
  34. NEXT: 'Y',
  35. REORIENT: {
  36. target: 'AB',
  37. actions: updateOrientation
  38. }
  39. }
  40. },
  41. AB: {
  42. on: {
  43. BACK: 'X',
  44. NEXT: 'Y',
  45. REORIENT: { actions: updateOrientation }
  46. }
  47. },
  48. Y: {
  49. type: 'final',
  50. }
  51. }
  52. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement