Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type alias WithContent =
- { contentItem : Content }
- type alias WithSelectedModel =
- { contentModel : ContentModel
- , overlay : Overlay.Model
- }
- type alias WithInlineEditor =
- { inlineEditorStyle : Animation.State
- }
- type Mode
- = Loading
- | Explore WithContent
- | Markdown WithContent WithSelectedModel
- | Preview WithContent WithSelectedModel
- | Wysiwyg WithContent WithSelectedModel WithInlineEditor
- type alias Model =
- { mode : Mode
- , menu : Menu
- }
- maybeLoading : Mode -> Maybe Mode
- maybeLoading state =
- case state of
- Loading ->
- Just state
- _ ->
- Nothing
- -- ... more maybeState functions
- mapWhenWithContent : (WithContent -> a) -> Mode -> Maybe a
- mapWhenWithContent func state =
- case state of
- Explore content ->
- Just <| func content
- Markdown content _ ->
- Just <| func content
- Preview content _ ->
- Just <| func content
- Wysiwyg content _ _ ->
- Just <| func content
- _ ->
- Nothing
- -- ... More mapWhen functions
- updateWhenWithContent : (WithContent -> WithContent) -> Mode -> Maybe Mode
- updateWhenWithContent func state =
- case state of
- Explore content ->
- func content |> Explore |> Just
- Markdown content selected ->
- func content |> (flip Markdown) selected |> Just
- Preview content selected ->
- func content |> (flip Preview) selected |> Just
- Wysiwyg content selected inline ->
- func content |> (swirll Wysiwyg) selected inline |> Just
- _ ->
- Nothing
- -- ... More updateWhen functions
- toLoading : Mode -> Mode
- toLoading _ =
- Loading
- -- State transition functions - these may contain custom logic, unlike the above which area really just boilerplate.
- toExplore : WithContent -> Mode -> Maybe Mode
- toExplore content state =
- case state of
- Loading ->
- Nothing
- _ ->
- Explore content |> Just
- toMarkdown : WithSelectedModel -> Mode -> Maybe Mode
- toMarkdown selected state =
- case state of
- Loading ->
- Nothing
- _ ->
- mapWhenWithContent
- (\content ->
- Markdown content selected
- )
- state
- toPreview : WithSelectedModel -> Mode -> Maybe Mode
- toPreview selected state =
- case state of
- Loading ->
- Nothing
- _ ->
- mapWhenWithContent
- (\content ->
- Preview content selected
- )
- state
- toWysiwyg : WithSelectedModel -> WithInlineEditor -> Mode -> Maybe Mode
- toWysiwyg selected inline state =
- case state of
- Loading ->
- Nothing
- _ ->
- mapWhenWithContent
- (\content ->
- Wysiwyg content selected inline
- )
- state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement