Created
December 1, 2015 13:06
-
-
Save emk/cee2f4f3873ffc13486a to your computer and use it in GitHub Desktop.
Elm case matching on complex records?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type alias Model = | |
{ errorMessage: Maybe String -- This is what Rails would call a "flash": we just show it. | |
, video: Maybe Video.Model -- Information about a video and subtitles. | |
, player: Maybe VideoPlayer.Model -- Player state: URL, playing/paused, time. | |
} | |
type Action | |
= VideoLoaded Video.Model | |
| VideoPlayerAction VideoPlayer.Action | |
view : Signal.Address Action -> Model -> Html.Html | |
view address model = | |
case model of | |
-- If we have an error, show that. | |
{ errorMessage = Just err } -> | |
text err | |
-- If we have a player, show that. | |
{ videoPlayer = Just player } -> | |
VideoPlayer.view (Signal.forwardTo address VideoPlayerAction) player | |
-- Otherwise, just show an error. | |
_ -> | |
text "Loading..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment