Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. type alias WithContent =
  2. { contentItem : Content }
  3.  
  4.  
  5. type alias WithSelectedModel =
  6. { contentModel : ContentModel
  7. , overlay : Overlay.Model
  8. }
  9.  
  10.  
  11. type alias WithInlineEditor =
  12. { inlineEditorStyle : Animation.State
  13. }
  14.  
  15.  
  16. type Mode
  17. = Loading
  18. | Explore WithContent
  19. | Markdown WithContent WithSelectedModel
  20. | Preview WithContent WithSelectedModel
  21. | Wysiwyg WithContent WithSelectedModel WithInlineEditor
  22.  
  23.  
  24. type alias Model =
  25. { mode : Mode
  26. , menu : Menu
  27. }
  28.  
  29.  
  30. maybeLoading : Mode -> Maybe Mode
  31. maybeLoading state =
  32. case state of
  33. Loading ->
  34. Just state
  35.  
  36. _ ->
  37. Nothing
  38.  
  39. -- ... more maybeState functions
  40.  
  41. mapWhenWithContent : (WithContent -> a) -> Mode -> Maybe a
  42. mapWhenWithContent func state =
  43. case state of
  44. Explore content ->
  45. Just <| func content
  46.  
  47. Markdown content _ ->
  48. Just <| func content
  49.  
  50. Preview content _ ->
  51. Just <| func content
  52.  
  53. Wysiwyg content _ _ ->
  54. Just <| func content
  55.  
  56. _ ->
  57. Nothing
  58.  
  59. -- ... More mapWhen functions
  60.  
  61. updateWhenWithContent : (WithContent -> WithContent) -> Mode -> Maybe Mode
  62. updateWhenWithContent func state =
  63. case state of
  64. Explore content ->
  65. func content |> Explore |> Just
  66.  
  67. Markdown content selected ->
  68. func content |> (flip Markdown) selected |> Just
  69.  
  70. Preview content selected ->
  71. func content |> (flip Preview) selected |> Just
  72.  
  73. Wysiwyg content selected inline ->
  74. func content |> (swirll Wysiwyg) selected inline |> Just
  75.  
  76. _ ->
  77. Nothing
  78.  
  79. -- ... More updateWhen functions
  80.  
  81. toLoading : Mode -> Mode
  82. toLoading _ =
  83. Loading
  84.  
  85. -- State transition functions - these may contain custom logic, unlike the above which area really just boilerplate.
  86.  
  87. toExplore : WithContent -> Mode -> Maybe Mode
  88. toExplore content state =
  89. case state of
  90. Loading ->
  91. Nothing
  92.  
  93. _ ->
  94. Explore content |> Just
  95.  
  96.  
  97. toMarkdown : WithSelectedModel -> Mode -> Maybe Mode
  98. toMarkdown selected state =
  99. case state of
  100. Loading ->
  101. Nothing
  102.  
  103. _ ->
  104. mapWhenWithContent
  105. (\content ->
  106. Markdown content selected
  107. )
  108. state
  109.  
  110.  
  111. toPreview : WithSelectedModel -> Mode -> Maybe Mode
  112. toPreview selected state =
  113. case state of
  114. Loading ->
  115. Nothing
  116.  
  117. _ ->
  118. mapWhenWithContent
  119. (\content ->
  120. Preview content selected
  121. )
  122. state
  123.  
  124.  
  125. toWysiwyg : WithSelectedModel -> WithInlineEditor -> Mode -> Maybe Mode
  126. toWysiwyg selected inline state =
  127. case state of
  128. Loading ->
  129. Nothing
  130.  
  131. _ ->
  132. mapWhenWithContent
  133. (\content ->
  134. Wysiwyg content selected inline
  135. )
  136. state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement