Internal types used to represent Elm Html in pure Elm
Type tree for representing Elm's Html
{ text : String }
Text tags just contain text
{ tag : String
, children : List (ElmHtml msg)
, facts : Facts msg
, descendantsCount : Basics.Int
}
A node contains the tag
as a string, the children, the facts (e.g attributes) and descendantsCount
{ facts : Facts msg
, model : Json.Decode.Value
}
Custom nodes contain facts (e.g attributes) and a json value for the model
{ facts : Facts msg
, model : ElmHtml.Markdown.MarkdownModel
}
A markdown node contains facts (e.g attributes) and the model used by markdown
{ styles : Dict String String
, events : Dict String (Json.Decode.Decoder msg)
, attributeNamespace : Maybe Json.Decode.Value
, stringAttributes : Dict String String
, boolAttributes : Dict String Basics.Bool
}
Facts contain various dictionaries and values for a node
Json.Decode.Value
Tagger holds the map function when Html.Map is used, the tagger should then be applied to events comming from descendant nodes, it is basically a javascript function.
Json.Decode.Value
EventHandler holds the function that is called when an event is triggered, it is basically a javascript object like this:
{ decoder: [Function] }
Type for representing the five kinds of elements according to HTML 5 spec. Used to handle different rendering behavior depending on the type of element.
Type for representing Elm's Attributes
Html.Attributes.colspan
. These values
are applied using element.setAttribute(key, value)
during a patch.Svg.Attributes.xlinkHref
Html.Attributes.class
, and can
hold any encoded value. Unlike attributes, where element.setAttribute()
is
used during the patch, properties are applied directly as
element[key] = value
.Html.Event.Options
for the event{ key : String
, value : String
}
Attribute contains a string key and a string value
{ key : String
, value : String
, namespace : String
}
NamespacedAttribute contains a string key, string namespace and string value
{ key : String
, value : Json.Decode.Value
}
Property contains a string key and a value with an arbitrary type
{ key : String
, decoder : Json.Decode.Value
, options : { stopPropagation : Basics.Bool
, preventDefault : Basics.Bool }
}
Event contains a string key, a decoder for a msg and event options
decodeElmHtml : (List Tagger -> EventHandler -> Json.Decode.Decoder msg) -> Json.Decode.Decoder (ElmHtml msg)
decode a json object into ElmHtml, you have to pass a function that decodes events from Html Nodes. If you don't want to decode event msgs, you can ignore it:
decodeElmHtml (_ _ -> ()) jsonHtml
if you do want to decode them, you will probably need to write some native code like elm-html-test does to extract the function inside those.
emptyFacts : Facts msg
Just empty facts
toElementKind : String -> ElementKind
Identify the kind of element. Helper to convert an tag name into a type for pattern matching.
decodeAttribute : Json.Decode.Decoder Attribute
Decode a JSON object into an Attribute. You have to pass a function that decodes events from event attributes. If you don't want to decode event msgs, you can ignore it:
decodeAttribute (\_ -> ()) jsonHtml
If you do want to decode them, you will probably need to write some native code like elm-html-test does to extract the function inside those.