diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-03-25 23:42:44 +0000 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-03-25 23:42:44 +0000 |
commit | 38d8535cf48ca5aa5edc8fe8f06f1ad32526b8b9 (patch) | |
tree | cef2bef4b1828123f832426cd00204b98032b24f | |
parent | d06db4c3fdc01b88b14c0f47ab9a32684f874fbd (diff) | |
download | lustre-38d8535cf48ca5aa5edc8fe8f06f1ad32526b8b9.tar.gz lustre-38d8535cf48ca5aa5edc8fe8f06f1ad32526b8b9.zip |
:memo: Touch on the difference between attributes and properties.
-rw-r--r-- | src/lustre/attribute.gleam | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lustre/attribute.gleam b/src/lustre/attribute.gleam index 58f49dc..5588c73 100644 --- a/src/lustre/attribute.gleam +++ b/src/lustre/attribute.gleam @@ -11,16 +11,28 @@ import lustre/internals/vdom.{Attribute, Event} /// The `Attribute` type encompasses HTML attributes, DOM properties, and /// event listeners. +/// pub type Attribute(msg) = vdom.Attribute(msg) // CONSTRUCTORS ---------------------------------------------------------------- +/// Create an HTML attribute. This is like saying `element.setAttribute("class", "wibble")` +/// in JavaScript. Attributes will be rendered when calling [`element.to_string`](./element.html#to_string). +/// +/// **Note**: there is a subtle difference between attributes and properties. You +/// can read more about the implications of this [here](https://javascript.info/dom-attributes-and-properties). /// pub fn attribute(name: String, value: String) -> Attribute(msg) { Attribute(name, dynamic.from(value), as_property: False) } +/// Create a DOM property. This is like saying `element.className = "wibble"` in +/// JavaScript. Properties will be **not** be rendered when calling +/// [`element.to_string`](./element.html#to_string). +/// +/// **Note**: there is a subtle difference between attributes and properties. You +/// can read more about the implications of this [here](https://javascript.info/dom-attributes-and-properties). /// pub fn property(name: String, value: any) -> Attribute(msg) { Attribute(name, dynamic.from(value), as_property: True) @@ -31,6 +43,9 @@ pub fn on(name: String, handler: Decoder(msg)) -> Attribute(msg) { Event("on" <> name, handler) } +/// Create an empty attribute. This is not added to the DOM and not rendered when +/// calling [`element.to_string`](./element.html#to_string), but it is useful for +/// _conditionally_ adding attributes to an element. /// pub fn none() -> Attribute(msg) { class("") |