miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Property

Description

Overview

Miso.Property provides the low-level primitives for constructing Attribute values that set DOM properties on virtual nodes. All higher-level property combinators in Miso.Html.Property, Miso.Svg.Property, and Miso.Mathml.Property are built on top of these.

The central combinator is prop:

prop :: ToJSON a => MisoString -> a -> Attribute action

It wraps any JSON-serialisable value as a Property node, which the virtual DOM diffs and writes to the DOM node only when the value changes.

Typed convenience wrappers

textProp
MisoString — textProp "placeholder" "…"
stringProp
String — stringProp "lang" "en"
boolProp
Bool — boolProp "checked" True
intProp
Int — intProp "tabIndex" 3
integerProp
Integer — integerProp "size" 10
doubleProp
Double — doubleProp "volume" 0.8
objectProp
Object — objectProp "dataset" obj

Class list

classList stores CSS class names as a deduplicated list rather than a single concatenated string. The virtual DOM diffing engine handles the list directly so individual class additions and removals are efficient:

classList ["btn", "btn-primary"]

Virtual DOM keys

key_ (alias keyProp) attaches a reconciliation key to a node, telling the differ which old and new nodes correspond to each other in a dynamic list:

ul_ []
  [ li_ [ key_ item.id ] [ text item.label ]
  | item <- items
  ]

See also

Synopsis

Smart constructors

prop Source #

Arguments

:: ToJSON a 
=> MisoString

DOM property name (e.g. "value", "className")

-> a

Property value; serialised to JSON before diffing

-> Attribute model action 

prop k v is an attribute that will set the attribute k of the DOM node associated with the vnode to v.

classList :: [MisoString] -> Attribute model action Source #

Smart constructor for specifying 'class'

Since: 1.9.0.0

textProp Source #

Arguments

:: MisoString

DOM property name

-> MisoString

Property value

-> Attribute model action 

Set field to MisoString value

stringProp Source #

Arguments

:: MisoString

DOM property name

-> String

Property value

-> Attribute model action 

Set field to String value

boolProp Source #

Arguments

:: MisoString

DOM property name

-> Bool

Property value

-> Attribute model action 

Set field to Bool value

intProp Source #

Arguments

:: MisoString

DOM property name

-> Int

Property value

-> Attribute model action 

Set field to Int value

integerProp Source #

Arguments

:: MisoString

DOM property name

-> Integer

Property value

-> Attribute model action 

Set field to Integer value

doubleProp Source #

Arguments

:: MisoString

DOM property name

-> Double

Property value

-> Attribute model action 

Set field to Double value

objectProp Source #

Arguments

:: MisoString

DOM property name

-> Object

JSON object value

-> Attribute model action 

Set field to Object value

keyProp :: ToKey key => key -> Attribute model action Source #

Set Key on VNode.

key_ :: ToKey key => key -> Attribute model action Source #

Synonym for keyProp Allows a user to specify a Key inside of an '[Attribute model action]'