Skip to content

Commit dfeeab5

Browse files
author
Steven Orvell
committed
Merge branch 'master' into remove-render-helpers
2 parents b7aaa77 + fafb487 commit dfeeab5

File tree

5 files changed

+84
-79
lines changed

5 files changed

+84
-79
lines changed

README.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,32 @@ and renders declaratively using `lit-html`.
2323
be performed when a property is set, for example validation. Call `requestUpdate(name, oldValue)`
2424
in the setter to trigger an update and use any configured property options.
2525

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
2727
process the property. This can be done either in the `@property({...})` decorator or in the
2828
object returned from the `properties` getter, e.g. `static get properties { return { foo: {...} }`.
2929

3030
Property options include:
3131

3232
* `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`).
3535
If a string, the string value is observed (e.g `attribute: 'foo-bar'`).
3636
* `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.
5152

5253
* **React to changes:** LitElement reacts to changes in properties and attributes by
5354
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
161162

162163
* `update(changedProperties)` (protected): This method calls `render()` and then uses `lit-html`
163164
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.
165166

166167
* `firstUpdated(changedProperties)`: (protected) Called after the element's DOM has been
167168
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
175176

176177
* `updateComplete`: Returns a Promise that resolves when the element has completed
177178
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.
180181
For example, it is sometimes useful to await a rendered element before fulfilling
181182
this Promise. To do this, first await `super.updateComplete` then any subsequent state.
182183

@@ -195,14 +196,15 @@ into the element. This is the only method that must be implemented by subclasses
195196

196197
## Advanced: Update Lifecycle
197198

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.
200202
* `requestUpdate()`: Updates the element after awaiting a [microtask](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/) (at the end
201203
of the event loop, before the next paint).
202204
* `shouldUpdate(changedProperties)`: The update proceeds if this returns `true`, which
203205
it does by default.
204206
* `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.
206208
* `render()`: Returns a `lit-html` TemplateResult (e.g. <code>html\`Hello ${world}\`</code>)
207209
to render element DOM. Setting properties inside this method will *not* trigger
208210
the element to update.
@@ -273,3 +275,8 @@ Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also
273275

274276
## Known Issues
275277

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).

package-lock.json

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
"devDependencies": {
2424
"@types/chai": "^4.0.1",
2525
"@types/mocha": "^5.2.4",
26-
"@webcomponents/webcomponentsjs": "^2.1.0",
26+
"@webcomponents/webcomponentsjs": "^2.1.1",
2727
"chai": "^4.0.2",
2828
"mocha": "^5.0.5",
2929
"rollup": "^0.64.1",
3030
"rollup-plugin-filesize": "^4.0.1",
31-
"rollup-plugin-node-resolve": "^3.3.0",
31+
"rollup-plugin-node-resolve": "^3.4.0",
3232
"rollup-plugin-terser": "^1.0.1",
3333
"tslint": "^5.7.0",
3434
"typedoc": "^0.8.0",
35-
"typescript": "^3.0.1",
35+
"typescript": "^3.0.3",
3636
"uglify-es": "^3.3.9",
3737
"wct-browser-legacy": "^1.0.1",
3838
"web-component-tester": "^6.8.0"
3939
},
4040
"typings": "lit-element.d.ts",
4141
"dependencies": {
42-
"lit-html": "^0.11.0"
42+
"lit-html": "^0.11.2"
4343
},
4444
"publishConfig": {
4545
"access": "public"

src/lib/updating-element.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface PropertyDeclaration<T = any> {
5959
* Indicates if the property should reflect to an attribute.
6060
* If `true`, when the property is set, the attribute is set using the
6161
* attribute name determined according to the rules for the `attribute`
62-
* propety option and the value of the property serialized using the rules from
62+
* property option and the value of the property serialized using the rules from
6363
* the `type` property option.
6464
*/
6565
reflect?: boolean;
@@ -325,7 +325,12 @@ export abstract class UpdatingElement extends HTMLElement {
325325
* Fixes any properties set on the instance before upgrade time.
326326
* Otherwise these would shadow the accessor and break these properties.
327327
* The properties are stored in a Map which is played back after the constructor
328-
* runs.
328+
* runs. Note, on very old versions of Safari (<=9) or Chrome (<=41), properties
329+
* created for native platform properties like (`id` or `name`) may not have default
330+
* values set in the element constructor. On these browsers native properties
331+
* appear on instances and therefore their default value will overwrite any element
332+
* default (e.g. if the element sets this.id = 'id' in the constructor, the 'id'
333+
* will become '' since this is the native platform default).
329334
*/
330335
private _saveInstanceProperties() {
331336
for (const [p] of (this.constructor as typeof UpdatingElement)._classProperties) {
@@ -520,13 +525,13 @@ export abstract class UpdatingElement extends HTMLElement {
520525
}
521526

522527
/**
523-
* Returns a Promise that resolves when the element has completed updating
524-
* that resolves to a boolean value that is `true` if the element completed
525-
* the update without triggering another update. This happens if a property
526-
* is set in `updated()`. This getter can be implemented to await additional
527-
* state. For example, it is sometimes useful to await a rendered element before
528-
* fulfilling this Promise. To do this, first await `super.updateComplete`
529-
* then any subsequent state.
528+
* Returns a Promise that resolves when the element has completed updating.
529+
* The Promise value is a boolean that is `true` if the element completed the
530+
* update without triggering another update. The Promise result is `false` if a
531+
* property was set inside `updated()`. This getter can be implemented to await
532+
* additional state. For example, it is sometimes useful to await a rendered
533+
* element before fulfilling this Promise. To do this, first await
534+
* `super.updateComplete` then any subsequent state.
530535
*
531536
* @returns {Promise} The Promise returns a boolean that indicates if the
532537
* update resolved without triggering another update.

0 commit comments

Comments
 (0)