Skip to content

Instantly share code, notes, and snippets.

@michaeljones
Last active May 18, 2016 20:07
Show Gist options
  • Save michaeljones/f2ba0275645f7e522f78f749a0a1dce8 to your computer and use it in GitHub Desktop.
Save michaeljones/f2ba0275645f7e522f78f749a0a1dce8 to your computer and use it in GitHub Desktop.
Elm - TypeError: Cannot read property 'decoder' of null
import Html.Events exposing (onClick)
import Html exposing (..)
import Html.App
type alias Model =
{ clicks : Int
}
type Msg
= Click
init : Model
init =
{ clicks = 0
}
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Click ->
( { model | clicks = model.clicks + 1 }, Cmd.none )
view : Model -> Html.Html Msg
view model =
div []
[ table []
[ tbody []
[ tr []
[ viewCell model
]
]
]
]
viewCell : Model -> Html.Html Msg
viewCell model =
-- Switching from having an onClick attribute to not having one appears to
-- result in a error on the next click
if model.clicks < 1 then
td [ onClick Click ]
[ div []
[ text "content ", text (toString model.clicks)
]
]
else
td []
[ div []
[ text "other content ", text (toString model.clicks)
]
]
main =
Html.App.program
{ init = ( init, Cmd.none )
, view = view
, update = update
, subscriptions = \model -> Sub.none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment