Skip to content

Instantly share code, notes, and snippets.

@colinmccabe
Last active May 4, 2016 00:08
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 colinmccabe/56abf3c8a602834401cac1933c38ba7f to your computer and use it in GitHub Desktop.
Save colinmccabe/56abf3c8a602834401cac1933c38ba7f to your computer and use it in GitHub Desktop.
{
"version": "0.1.0",
"summary": "",
"repository": "http://github.com/colinmccabe/html-bug.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
}
module Main exposing (main) -- where
import Html
import Html.App
import Platform.Cmd
import Time
type alias Model =
List String
init : (Model, Cmd a)
init =
( []
, Cmd.none
)
type Msg
= Tick Time.Time
| NoOp
update : Msg -> Model -> (Model, Cmd a)
update msg model =
case msg of
Tick time ->
( (toString time) :: model
, Cmd.none
)
NoOp ->
( model, Cmd.none )
main : Program Never
main =
Html.App.program
{ init = init
, update = update
, view = view
, subscriptions = \_ -> Time.every (500 * Time.millisecond) Tick
}
view : Model -> Html.Html Msg
view model =
let html =
-- I don't know why, but this case that returns either a div
-- or a table, passed to Html.App.map, causes an exception.
-- Remove either, and there is no exception.
case model of
[] ->
Html.div [] [ Html.text "No items, displaying div with text" ]
xs ->
viewTable xs
in
Html.App.map (\_ -> NoOp) html
viewTable : Model -> Html.Html a
viewTable model =
Html.table
[]
[ Html.thead
[]
[ Html.tr [] [ Html.text "Table:" ] ]
, Html.tbody
[]
(List.map (\item -> Html.tr [] [ Html.td [] [ Html.text item ] ]) model)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment