Skip to content

Commit c6f9b31

Browse files
author
Steven Orvell
committed
Adds _enableProperties as a new entry point that must be called to turn on properties. Prevents a bug where _readyClients can be called twice.
1 parent 90e8cd9 commit c6f9b31

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

lib/elements/dom-bind.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
for (let n=this.root.firstChild; n; n=n.nextSibling) {
104104
this.__children[this.__children.length] = n;
105105
}
106-
this._flushProperties();
106+
this._enableProperties();
107107
}
108108
this.__insertChildren();
109109
this.dispatchEvent(new CustomEvent('dom-change', {

lib/mixins/element-mixin.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,7 @@
631631
if (window.ShadyCSS && this._template) {
632632
window.ShadyCSS.styleElement(this);
633633
}
634-
if (!this.__dataInitialized) {
635-
this._flushProperties();
636-
}
634+
this._enableProperties();
637635
}
638636

639637
/**

lib/mixins/property-accessors.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,18 @@
475475
}
476476
}
477477

478+
// TODO(kschaaf): document.
479+
_enableProperties() {
480+
if (!this.__dataPropertiesEnabled) {
481+
this.__dataPropertiesEnabled = true;
482+
if (this.__dataInstanceProps) {
483+
this._initializeInstanceProperties(this.__dataInstanceProps);
484+
this.__dataInstanceProps = null;
485+
}
486+
this.ready()
487+
}
488+
}
489+
478490
/**
479491
* Calls the `_propertiesChanged` callback with the current set of
480492
* pending changes (and old values recorded when pending changes were
@@ -487,9 +499,7 @@
487499
* @protected
488500
*/
489501
_flushProperties() {
490-
if (!this.__dataInitialized) {
491-
this.ready()
492-
} else if (this.__dataPending) {
502+
if (this.__dataPending) {
493503
let changedProps = this.__dataPending;
494504
this.__dataPending = null;
495505
this.__dataCounter++;
@@ -513,12 +523,6 @@
513523
* @public
514524
*/
515525
ready() {
516-
// Update instance properties that shadowed proto accessors; these take
517-
// priority over any defaults set in constructor or attributeChangedCallback
518-
if (this.__dataInstanceProps) {
519-
this._initializeInstanceProperties(this.__dataInstanceProps);
520-
this.__dataInstanceProps = null;
521-
}
522526
this.__dataInitialized = true;
523527
// Run normal flush
524528
this._flushProperties();

lib/mixins/property-effects.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,8 @@
230230
// And the host has already initialized clients; this prevents
231231
// an issue with a host observing data changes before clients are ready.
232232
let host;
233-
if (notified && (host = inst.__dataHost) && host._flushProperties
234-
&& host.__dataClientsInitialized) {
235-
host._flushProperties();
233+
if (notified && (host = inst.__dataHost) && host._invalidateProperties) {
234+
host._invalidateProperties();
236235
}
237236
}
238237

@@ -1430,6 +1429,7 @@
14301429
*/
14311430
_flushClients() {
14321431
if (!this.__dataClientsInitialized) {
1432+
this.__dataClientsInitialized = true;
14331433
this._readyClients();
14341434
}
14351435
// Flush all clients
@@ -1438,7 +1438,10 @@
14381438
this.__dataPendingClients = null;
14391439
for (let i=0; i < clients.length; i++) {
14401440
let client = clients[i];
1441-
if (!client.__dataInitialized || client.__dataPending) {
1441+
// boot up client if necessary, otherwise flush properties
1442+
if (!client.__dataPropertiesEnabled) {
1443+
client._enableProperties();
1444+
} else if (client.__dataPending) {
14421445
client._flushProperties();
14431446
}
14441447
}
@@ -1479,9 +1482,9 @@
14791482
* @override
14801483
*/
14811484
ready() {
1482-
super.ready();
1485+
this._flushProperties();
14831486
if (!this.__dataClientsInitialized) {
1484-
this._readyClients();
1487+
this._flushClients();
14851488
}
14861489
// Before ready, client notifications do not trigger _flushProperties.
14871490
// Therefore a flush is necessary here if data has been set.
@@ -1498,7 +1501,7 @@
14981501
* @protected
14991502
*/
15001503
_readyClients() {
1501-
this.__dataClientsInitialized = true;
1504+
this.__dataInitialized = true;
15021505
}
15031506

15041507
/**

lib/utils/templatize.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
// or when there isn't instance props.
6464
let options = this.__templatizeOptions;
6565
if ((props && options.instanceProps) || !options.instanceProps) {
66-
this._flushProperties();
66+
this._enableProperties();
6767
}
6868
}
6969
/**
@@ -251,7 +251,7 @@
251251
template.__dataTemp = {};
252252
template.__dataPending = null;
253253
template.__dataOld = null;
254-
template._flushProperties();
254+
template._enableProperties();
255255
}
256256
}
257257

test/unit/property-accessors.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
this._propertiesChanged = sinon.spy();
3030
}
3131
connectedCallback() {
32-
this._flushProperties();
32+
this._enableProperties();
3333
}
3434
}
3535
XFoo.createPropertiesForAttributes();

test/unit/property-effects.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@
15141514
BaseClass = class extends Polymer.PropertyEffects(HTMLElement) {
15151515
connectedCallback() {
15161516
this.pcSpy = sinon.spy();
1517-
this._flushProperties();
1517+
this._enableProperties();
15181518
}
15191519
_propertiesChanged(props, changedProps, oldProps) {
15201520
this.pcSpy(props, changedProps, oldProps);

0 commit comments

Comments
 (0)