Skip to content

Instantly share code, notes, and snippets.

@emk
Created December 1, 2015 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emk/cee2f4f3873ffc13486a to your computer and use it in GitHub Desktop.
Save emk/cee2f4f3873ffc13486a to your computer and use it in GitHub Desktop.
Elm case matching on complex records?
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