Skip to content

Commit 0eda741

Browse files
Prepare 2.3.0 release (#933)
* Prepare 2.3.0 release * Format * Fix formatting
1 parent 5a421e1 commit 0eda741

7 files changed

+126
-113
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
<!-- ### Removed -->
1717
<!-- ### Fixed -->
1818

19-
## [2.3.0-pre.1] - 2020-03-17
19+
## [2.3.0] - 2020-03-18
2020

2121
### Changed
2222
* Added a static `getPropertyDescriptor` method to allow easier customization of property accessors. This method should return a a `PropertyDescriptor` to install on the property. If no descriptor is returned, no property accessor is created. ([#911](https://github.com/Polymer/lit-element/issues/911))

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lit-element",
3-
"version": "2.3.0-pre.1",
3+
"version": "2.3.0",
44
"description": "A simple base class for creating fast, lightweight web components",
55
"license": "BSD-3-Clause",
66
"homepage": "https://lit-element.polymer-project.org/",

src/lib/decorators.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ export function queryAsync(selector: string) {
286286
*
287287
* @param selector A DOMString containing one or more selectors to match.
288288
*
289-
* See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
289+
* See:
290+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
290291
*
291292
* @example
292293
*

src/lib/updating-element.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export interface ComplexAttributeConverter<Type = unknown, TypeHint = unknown> {
5151
}
5252

5353
type AttributeConverter<Type = unknown, TypeHint = unknown> =
54-
ComplexAttributeConverter<Type>|((value: string|null, type?: TypeHint) => Type);
54+
ComplexAttributeConverter<Type>|
55+
((value: string|null, type?: TypeHint) => Type);
5556

5657
/**
5758
* Defines options for a property accessor.
@@ -112,7 +113,6 @@ export interface PropertyDeclaration<Type = unknown, TypeHint = unknown> {
112113
* the property changes.
113114
*/
114115
readonly noAccessor?: boolean;
115-
116116
}
117117

118118
/**
@@ -333,7 +333,8 @@ export abstract class UpdatingElement extends HTMLElement {
333333
*
334334
* class MyElement extends LitElement {
335335
* static getPropertyDescriptor(name, key, options) {
336-
* const defaultDescriptor = super.getPropertyDescriptor(name, key, options);
336+
* const defaultDescriptor =
337+
* super.getPropertyDescriptor(name, key, options);
337338
* const setter = defaultDescriptor.set;
338339
* return {
339340
* get: defaultDescriptor.get,
@@ -349,8 +350,8 @@ export abstract class UpdatingElement extends HTMLElement {
349350
*
350351
* @nocollapse
351352
*/
352-
protected static getPropertyDescriptor(name: PropertyKey,
353-
key: string|symbol, _options: PropertyDeclaration) {
353+
protected static getPropertyDescriptor(
354+
name: PropertyKey, key: string|symbol, _options: PropertyDeclaration) {
354355
return {
355356
// tslint:disable-next-line:no-any no symbol in index
356357
get(): any {
@@ -381,7 +382,7 @@ export abstract class UpdatingElement extends HTMLElement {
381382
*/
382383
protected static getPropertyOptions(name: PropertyKey) {
383384
return this._classProperties && this._classProperties.get(name) ||
384-
defaultPropertyDeclaration;
385+
defaultPropertyDeclaration;
385386
}
386387

387388
/**

src/lit-element.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare global {
3131
// This line will be used in regexes to search for LitElement usage.
3232
// TODO(justinfagnani): inject version number at build time
3333
(window['litElementVersions'] || (window['litElementVersions'] = []))
34-
.push('2.3.0-pre.1');
34+
.push('2.3.0');
3535

3636
export interface CSSResultArray extends Array<CSSResult|CSSResultArray> {}
3737

src/test/lib/decorators_test.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -461,22 +461,20 @@ suite('decorators', () => {
461461
});
462462

463463
suite('@queryAsync', () => {
464-
465464
@customElement(generateElementName() as keyof HTMLElementTagNameMap)
466465
class C extends LitElement {
467466
@queryAsync('#blah') blah!: Promise<HTMLDivElement>;
468467

469468
@queryAsync('span') nope!: Promise<HTMLSpanElement|null>;
470469

471-
@property()
472-
foo = false;
470+
@property() foo = false;
473471

474472
render() {
475473
return html`
476474
<div>Not this one</div>
477-
${this.foo ?
478-
html`<div id="blah" foo>This one</div>` :
479-
html`<div id="blah">This one</div>` }
475+
${
476+
this.foo ? html`<div id="blah" foo>This one</div>` :
477+
html`<div id="blah">This one</div>`}
480478
`;
481479
}
482480
}

src/test/lib/updating-element_test.ts

+110-97
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* http://polymer.github.io/PATENTS.txt
1313
*/
1414

15-
import {property, customElement} from '../../lib/decorators.js';
16-
import {ComplexAttributeConverter, PropertyDeclarations, PropertyValues, UpdatingElement, PropertyDeclaration, defaultConverter} from '../../lib/updating-element.js';
15+
import {customElement, property} from '../../lib/decorators.js';
16+
import {ComplexAttributeConverter, defaultConverter, PropertyDeclaration, PropertyDeclarations, PropertyValues, UpdatingElement} from '../../lib/updating-element.js';
1717
import {generateElementName} from '../test-helpers.js';
1818

1919
// tslint:disable:no-any ok in tests
@@ -1429,36 +1429,39 @@ suite('UpdatingElement', () => {
14291429
assert.equal(el.updatedText, '6');
14301430
});
14311431

1432-
test('setting properties in update after calling `super.update` *does* trigger update', async () => {
1433-
class E extends UpdatingElement {
1434-
static get properties() {
1435-
return {foo: {}};
1436-
}
1437-
promiseFulfilled = false;
1438-
foo = 0;
1439-
updateCount = 0;
1440-
updatedText = '';
1432+
test(
1433+
'setting properties in update after calling `super.update` *does* trigger update',
1434+
async () => {
1435+
class E extends UpdatingElement {
1436+
static get properties() {
1437+
return {foo: {}};
1438+
}
1439+
promiseFulfilled = false;
1440+
foo = 0;
1441+
updateCount = 0;
1442+
updatedText = '';
14411443

1442-
update(props: PropertyValues) {
1443-
this.updateCount++;
1444-
super.update(props);
1445-
if (this.foo < 1) {
1446-
this.foo++;
1447-
}
1448-
}
1444+
update(props: PropertyValues) {
1445+
this.updateCount++;
1446+
super.update(props);
1447+
if (this.foo < 1) {
1448+
this.foo++;
1449+
}
1450+
}
14491451

1450-
updated() {
1451-
this.updatedText = `${this.foo}`;
1452-
}
1453-
}
1454-
customElements.define(generateElementName(), E);
1455-
const el = new E();
1456-
container.appendChild(el);
1457-
while (!(await el.updateComplete)) {}
1458-
assert.equal(el.foo, 1);
1459-
assert.equal(el.updateCount, 2);
1460-
assert.equal(el.updatedText, '1');
1461-
});
1452+
updated() {
1453+
this.updatedText = `${this.foo}`;
1454+
}
1455+
}
1456+
customElements.define(generateElementName(), E);
1457+
const el = new E();
1458+
container.appendChild(el);
1459+
while (!(await el.updateComplete)) {
1460+
}
1461+
assert.equal(el.foo, 1);
1462+
assert.equal(el.updateCount, 2);
1463+
assert.equal(el.updatedText, '1');
1464+
});
14621465

14631466
test(
14641467
'setting properties in update reflects to attribute and is included in `changedProperties`',
@@ -1802,68 +1805,62 @@ suite('UpdatingElement', () => {
18021805
assert.equal(sub.getAttribute('foo'), '5');
18031806
});
18041807

1805-
test('can provide a default property declaration', async () => {
1806-
1807-
const SpecialNumber = {};
1808-
1809-
const myPropertyDeclaration = {
1810-
type: SpecialNumber,
1811-
reflect: true,
1812-
converter: {
1813-
toAttribute: function(value: unknown, type?: unknown): unknown {
1814-
switch (type) {
1815-
case String:
1816-
return value === undefined ? null : value;
1817-
default:
1818-
return defaultConverter.toAttribute!(value, type);
1819-
}
1820-
},
1821-
fromAttribute: function(value: string|null, type?: unknown) {
1822-
switch (type) {
1823-
case SpecialNumber:
1824-
return Number(value) + 10;
1825-
default:
1826-
return defaultConverter.fromAttribute!(value, type);
1827-
}
1828-
}
1808+
test('can provide a default property declaration', async () => {
1809+
const SpecialNumber = {};
1810+
1811+
const myPropertyDeclaration = {
1812+
type: SpecialNumber,
1813+
reflect: true,
1814+
converter: {
1815+
toAttribute: function(value: unknown, type?: unknown): unknown {
1816+
switch (type) {
1817+
case String:
1818+
return value === undefined ? null : value;
1819+
default:
1820+
return defaultConverter.toAttribute!(value, type);
18291821
}
1830-
};
1831-
1832-
@customElement(generateElementName())
1833-
class E extends UpdatingElement {
1834-
1835-
static createProperty(
1836-
name: PropertyKey,
1837-
options: PropertyDeclaration) {
1838-
// Always mix into defaults to preserve custom converter.
1839-
options = Object.assign(Object.create(myPropertyDeclaration), options);
1840-
super.createProperty(name, options);
1822+
},
1823+
fromAttribute: function(value: string|null, type?: unknown) {
1824+
switch (type) {
1825+
case SpecialNumber:
1826+
return Number(value) + 10;
1827+
default:
1828+
return defaultConverter.fromAttribute!(value, type);
18411829
}
1830+
}
1831+
}
1832+
};
18421833

1843-
@property()
1844-
foo = 5;
1834+
@customElement(generateElementName())
1835+
class E extends UpdatingElement {
1836+
static createProperty(name: PropertyKey, options: PropertyDeclaration) {
1837+
// Always mix into defaults to preserve custom converter.
1838+
options = Object.assign(Object.create(myPropertyDeclaration), options);
1839+
super.createProperty(name, options);
1840+
}
18451841

1846-
@property({type: String})
1847-
bar?: string = 'bar';
1848-
}
1842+
@property() foo = 5;
18491843

1850-
const el = new E();
1851-
container.appendChild(el);
1852-
el.setAttribute('foo', '10');
1853-
el.setAttribute('bar', 'attrBar');
1854-
await el.updateComplete;
1855-
assert.equal(el.foo, 20);
1856-
assert.equal(el.bar, 'attrBar');
1857-
el.foo = 5;
1858-
el.bar = undefined;
1859-
await el.updateComplete;
1860-
assert.equal(el.getAttribute('foo'), '5');
1861-
assert.isFalse(el.hasAttribute('bar'));
1862-
});
1844+
@property({type: String}) bar?: string = 'bar';
1845+
}
18631846

1864-
test('can customize property options and accessor creation', async () => {
1847+
const el = new E();
1848+
container.appendChild(el);
1849+
el.setAttribute('foo', '10');
1850+
el.setAttribute('bar', 'attrBar');
1851+
await el.updateComplete;
1852+
assert.equal(el.foo, 20);
1853+
assert.equal(el.bar, 'attrBar');
1854+
el.foo = 5;
1855+
el.bar = undefined;
1856+
await el.updateComplete;
1857+
assert.equal(el.getAttribute('foo'), '5');
1858+
assert.isFalse(el.hasAttribute('bar'));
1859+
});
18651860

1866-
interface MyPropertyDeclaration<TypeHint = unknown> extends PropertyDeclaration {
1861+
test('can customize property options and accessor creation', async () => {
1862+
interface MyPropertyDeclaration<TypeHint = unknown> extends
1863+
PropertyDeclaration {
18671864
validator?: (value: any) => TypeHint;
18681865
observer?: (oldValue: TypeHint) => void;
18691866
}
@@ -1876,18 +1873,21 @@ suite('UpdatingElement', () => {
18761873

18771874
@customElement(generateElementName())
18781875
class E extends UpdatingElement {
1879-
1880-
static getPropertyDescriptor(name: PropertyKey, key: string|symbol, options: MyPropertyDeclaration) {
1881-
const defaultDescriptor = super.getPropertyDescriptor(name, key, options);
1876+
static getPropertyDescriptor(
1877+
name: PropertyKey, key: string|symbol,
1878+
options: MyPropertyDeclaration) {
1879+
const defaultDescriptor =
1880+
super.getPropertyDescriptor(name, key, options);
18821881
return {
18831882
get: defaultDescriptor.get,
18841883
set(this: E, value: unknown) {
18851884
const oldValue =
1886-
(this as unknown as {[key: string]: unknown})[name as string];
1885+
(this as unknown as {[key: string]: unknown})[name as string];
18871886
if (options.validator) {
18881887
value = options.validator(value);
18891888
}
1890-
(this as unknown as {[key: string]: unknown})[key as string] = value;
1889+
(this as unknown as {[key: string]: unknown})[key as string] =
1890+
value;
18911891
(this as unknown as UpdatingElement).requestUpdate(name, oldValue);
18921892
},
18931893

@@ -1900,7 +1900,7 @@ suite('UpdatingElement', () => {
19001900
super.updated(changedProperties);
19011901
changedProperties.forEach((value: unknown, key: PropertyKey) => {
19021902
const options = (this.constructor as typeof UpdatingElement)
1903-
.getPropertyOptions(key) as MyPropertyDeclaration;
1903+
.getPropertyOptions(key) as MyPropertyDeclaration;
19041904
const observer = options.observer;
19051905
if (typeof observer === 'function') {
19061906
observer.call(this, value);
@@ -1909,11 +1909,13 @@ suite('UpdatingElement', () => {
19091909
}
19101910

19111911
// provide custom deorator expecting extended type
1912-
@myProperty({type: Number, validator: (value: number) => Math.min(10, Math.max(value, 0))})
1912+
@myProperty({
1913+
type: Number,
1914+
validator: (value: number) => Math.min(10, Math.max(value, 0))
1915+
})
19131916
foo = 5;
19141917

1915-
@property({})
1916-
bar = 'bar';
1918+
@property({}) bar = 'bar';
19171919

19181920
// tslint:disable-next-line:no-any
19191921
_observedZot?: any;
@@ -1922,7 +1924,11 @@ suite('UpdatingElement', () => {
19221924
_observedZot2?: any;
19231925

19241926
// use regular decorator and cast to type
1925-
@property({observer: function(this: E, oldValue: string) { this._observedZot = {value: this.zot, oldValue}; } } as PropertyDeclaration)
1927+
@property({
1928+
observer: function(this: E, oldValue: string) {
1929+
this._observedZot = {value: this.zot, oldValue};
1930+
}
1931+
} as PropertyDeclaration)
19261932
zot = '';
19271933

19281934
zot2 = '';
@@ -1933,9 +1939,16 @@ suite('UpdatingElement', () => {
19331939
static get properties(): MyPropertyDeclarations {
19341940
return {
19351941
// object cast as type
1936-
zot2: {observer: function(this: E, oldValue: string) { this._observedZot2 = {value: this.zot2, oldValue}; } } as PropertyDeclaration,
1942+
zot2: {
1943+
observer: function(this: E, oldValue: string) {
1944+
this._observedZot2 = {value: this.zot2, oldValue};
1945+
}
1946+
} as PropertyDeclaration,
19371947
// object satisfying defined custom type.
1938-
foo2: {type: Number, validator: (value: number) => Math.min(10, Math.max(value, 0))}
1948+
foo2: {
1949+
type: Number,
1950+
validator: (value: number) => Math.min(10, Math.max(value, 0))
1951+
}
19391952
};
19401953
}
19411954
}

0 commit comments

Comments
 (0)