You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-18Lines changed: 19 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,31 +23,32 @@ and renders declaratively using `lit-html`.
23
23
be performed when a property is set, for example validation. Call `requestUpdate(name, oldValue)`
24
24
in the setter to trigger an update and use any configured property options.
25
25
26
-
Properties can be given an options argument which is an object that describes how to
26
+
Properties can be given an `options` argument which is an object that describes how to
27
27
process the property. This can be done either in the `@property({...})` decorator or in the
28
28
object returned from the `properties` getter, e.g. `static get properties { return { foo: {...} }`.
29
29
30
30
Property options include:
31
31
32
32
*`attribute`: Indicates how and whether the property becomes an observed attribute.
33
-
If the value is `false`, the property is not added to `observedAttributes`.
34
-
If true or absent, the lowercased property name is observed (e.g. `fooBar` becomes `foobar`).
33
+
If the value is `false`, the property is not added to the static `observedAttributes` getter.
34
+
If `true` or absent, the lowercased property name is observed (e.g. `fooBar` becomes `foobar`).
35
35
If a string, the string value is observed (e.g `attribute: 'foo-bar'`).
36
36
*`type`: Indicates how to serialize and deserialize the attribute to/from a property.
37
-
If this value is a function, it is used to deserialize the attribute value
38
-
a the property value. If it's an object, it can have keys for `fromAttribute` and
39
-
`toAttribute` where `fromAttribute` is the deserialize function and `toAttribute`
40
-
is a serialize function used to set the property to an attribute. If no `toAttribute`
41
-
function is provided and `reflect` is set to `true`, the property value is set
42
-
directly to the attribute.
43
-
*`reflect`: Indicates if the property should reflect to an attribute.
44
-
If `true`, when the property is set, the attribute is set using the
45
-
attribute name determined according to the rules for the `attribute`
46
-
property option and the value of the property serialized using the rules from
47
-
the `type` property option.
48
-
*`hasChanged`: A function that indicates if a property should be considered
49
-
changed when it is set. The function should take the `newValue` and `oldValue`
50
-
and return `true` if an update should be requested.
37
+
The value can be a function used for both serialization and deserialization, or it can
38
+
be an object with individual functions via the optional keys, `fromAttribute` and `toAttribute`.
39
+
`type` defaults to the `String` constructor, and so does the `toAttribute` and `fromAttribute`
40
+
keys.
41
+
*`reflect`: Indicates whether the property should reflect to its associated
42
+
attribute (as determined by the attribute option).
43
+
If `true`, when the property is set, the attribute which name is determined
44
+
according to the rules for the `attribute` property option, will be set to the
45
+
value of the property serialized using the rules from the `type` property option.
46
+
Note, `type: Boolean` has special handling by default which means that truthy
47
+
values result in the presense of the attribute, where as falsy values result
48
+
in the absense of the attribute.
49
+
*`hasChanged`: A function that indicates whether a property should be considered
50
+
changed when it is set and thus result in an update. The function should take the
51
+
`newValue` and `oldValue` and return `true` if an update should be requested.
51
52
52
53
***React to changes:** LitElement reacts to changes in properties and attributes by
53
54
asynchronously rendering, ensuring changes are batched. This reduces overhead
@@ -197,7 +198,7 @@ into the element. This is the only method that must be implemented by subclasses
197
198
198
199
* A property is set (e.g. `element.foo = 5`).
199
200
* If the property's `hasChanged(value, oldValue)` returns `false`, the element does not
200
-
update. If it returns `true`, `requestUdpate()` is called to schedule an update.
201
+
update. If it returns `true`, `requestUpdate()` is called to schedule an update.
201
202
*`requestUpdate()`: Updates the element after awaiting a [microtask](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/) (at the end
202
203
of the event loop, before the next paint).
203
204
*`shouldUpdate(changedProperties)`: The update proceeds if this returns `true`, which
0 commit comments