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
+30-23Lines changed: 30 additions & 23 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
-
propety 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
@@ -161,7 +162,7 @@ into the element. This is the only method that must be implemented by subclasses
161
162
162
163
*`update(changedProperties)` (protected): This method calls `render()` and then uses `lit-html`
163
164
in order to render the template DOM. It also updates any reflected attributes based on
164
-
property values. Setting properties inside this method will *not* trigger another update..
165
+
property values. Setting properties inside this method will *not* trigger another update.
165
166
166
167
*`firstUpdated(changedProperties)`: (protected) Called after the element's DOM has been
167
168
updated the first time, immediately before `updated()` is called.
@@ -175,8 +176,8 @@ into the element. This is the only method that must be implemented by subclasses
175
176
176
177
*`updateComplete`: Returns a Promise that resolves when the element has completed
177
178
updating. The Promise value is a boolean that is `true` if the element completed the
178
-
update without triggering another update. This happens if a property is set inside
179
-
`updated()`. This getter can be implemented to await additional state.
179
+
update without triggering another update. The Promise result is `false` if a
180
+
property was set inside `updated()`. This getter can be implemented to await additional state.
180
181
For example, it is sometimes useful to await a rendered element before fulfilling
181
182
this Promise. To do this, first await `super.updateComplete` then any subsequent state.
182
183
@@ -195,14 +196,15 @@ into the element. This is the only method that must be implemented by subclasses
195
196
196
197
## Advanced: Update Lifecycle
197
198
198
-
* When the element is first connected or a property is set (e.g. `element.foo = 5`)
199
-
and the property's `hasChanged(value, oldValue)` returns `true`.
199
+
* A property is set (e.g. `element.foo = 5`).
200
+
* If the property's `hasChanged(value, oldValue)` returns `false`, the element does not
201
+
update. If it returns `true`, `requestUpdate()` is called to schedule an update.
200
202
*`requestUpdate()`: Updates the element after awaiting a [microtask](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/) (at the end
201
203
of the event loop, before the next paint).
202
204
*`shouldUpdate(changedProperties)`: The update proceeds if this returns `true`, which
203
205
it does by default.
204
206
*`update(changedProperties)`: Updates the element. Setting properties inside this
205
-
method will *not* trigger the element to update.
207
+
method will *not* trigger another update.
206
208
*`render()`: Returns a `lit-html` TemplateResult (e.g. <code>html\`Hello ${world}\`</code>)
207
209
to render element DOM. Setting properties inside this method will *not* trigger
208
210
the element to update.
@@ -273,3 +275,8 @@ Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also
273
275
274
276
## Known Issues
275
277
278
+
* On very old versions of Safari (<=9) or Chrome (<=41), properties created for native
279
+
platform properties like (`id` or `name`) may not have default values set in the element constructor.
280
+
On these browsers native properties appear on instances and therefore their default value
281
+
will overwrite any element default (e.g. if the element sets this.id = 'id' in the constructor,
282
+
the 'id' will become '' since this is the native platform default).
0 commit comments