Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YetAnotherMinion/bfc9fec6cdc86374424c6c75cc2929af to your computer and use it in GitHub Desktop.
Save YetAnotherMinion/bfc9fec6cdc86374424c6c75cc2929af to your computer and use it in GitHub Desktop.
Html.Lazy problems
module LazyMarkdownBugReproduction exposing (main)
import Array exposing (Array)
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Lazy
import Html.Events exposing (onInput)
import Markdown
import Time exposing (Time)
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- MODEL
type alias Taco =
{ translations : Dict String String
, currentTime : Time
}
type alias Model =
{ description : Array String
, other : String
, taco : Taco
}
init : (Model, Cmd Msg)
init =
{ description = Array.fromList ["# Foo\n\n## Bar\n"]
, other = "Other"
, taco =
{ translations = Dict.empty
, currentTime = 0
}
}
! []
-- UPDATE
type Msg
= SetTime Time
| SetOther String
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
SetTime currentTime ->
let
taco =
model.taco
in
{ model | taco = { taco | currentTime = currentTime } } ! []
SetOther value ->
{ model | other = value } ! []
-- VIEW
view : Model -> Html Msg
view model =
div []
[ input [ onInput SetOther, defaultValue model.other ] []
, Html.Lazy.lazy
(\d ->
let
_ = Debug.log "description changed" d
in
Markdown.toHtmlWith
{ githubFlavored =
Just { tables = False, breaks = False }
, defaultHighlighting = Just "elm"
, sanitize = True
, smartypants = False
}
[]
d
)
(Maybe.withDefault "" (Array.get 0 model.description))
]
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every (20 * Time.second) SetTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment