Skip to content

Commit

Permalink
Adds _enableProperties as a new entry point that must be called to …
Browse files Browse the repository at this point in the history
…turn on properties. Prevents a bug where `_readyClients` can be called twice.
  • Loading branch information
Steven Orvell committed May 12, 2017
1 parent 90e8cd9 commit c6f9b31
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/elements/dom-bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
for (let n=this.root.firstChild; n; n=n.nextSibling) {
this.__children[this.__children.length] = n;
}
this._flushProperties();
this._enableProperties();
}
this.__insertChildren();
this.dispatchEvent(new CustomEvent('dom-change', {
Expand Down
4 changes: 1 addition & 3 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,7 @@
if (window.ShadyCSS && this._template) {
window.ShadyCSS.styleElement(this);
}
if (!this.__dataInitialized) {
this._flushProperties();
}
this._enableProperties();
}

/**
Expand Down
22 changes: 13 additions & 9 deletions lib/mixins/property-accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,18 @@
}
}

// TODO(kschaaf): document.
_enableProperties() {
if (!this.__dataPropertiesEnabled) {
this.__dataPropertiesEnabled = true;
if (this.__dataInstanceProps) {
this._initializeInstanceProperties(this.__dataInstanceProps);
this.__dataInstanceProps = null;
}
this.ready()
}
}

/**
* Calls the `_propertiesChanged` callback with the current set of
* pending changes (and old values recorded when pending changes were
Expand All @@ -487,9 +499,7 @@
* @protected
*/
_flushProperties() {
if (!this.__dataInitialized) {
this.ready()
} else if (this.__dataPending) {
if (this.__dataPending) {
let changedProps = this.__dataPending;
this.__dataPending = null;
this.__dataCounter++;
Expand All @@ -513,12 +523,6 @@
* @public
*/
ready() {
// Update instance properties that shadowed proto accessors; these take
// priority over any defaults set in constructor or attributeChangedCallback
if (this.__dataInstanceProps) {
this._initializeInstanceProperties(this.__dataInstanceProps);
this.__dataInstanceProps = null;
}
this.__dataInitialized = true;
// Run normal flush
this._flushProperties();
Expand Down
17 changes: 10 additions & 7 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@
// And the host has already initialized clients; this prevents
// an issue with a host observing data changes before clients are ready.
let host;
if (notified && (host = inst.__dataHost) && host._flushProperties
&& host.__dataClientsInitialized) {
host._flushProperties();
if (notified && (host = inst.__dataHost) && host._invalidateProperties) {
host._invalidateProperties();
}
}

Expand Down Expand Up @@ -1430,6 +1429,7 @@
*/
_flushClients() {
if (!this.__dataClientsInitialized) {
this.__dataClientsInitialized = true;
this._readyClients();
}
// Flush all clients
Expand All @@ -1438,7 +1438,10 @@
this.__dataPendingClients = null;
for (let i=0; i < clients.length; i++) {
let client = clients[i];
if (!client.__dataInitialized || client.__dataPending) {
// boot up client if necessary, otherwise flush properties
if (!client.__dataPropertiesEnabled) {
client._enableProperties();
} else if (client.__dataPending) {
client._flushProperties();
}
}
Expand Down Expand Up @@ -1479,9 +1482,9 @@
* @override
*/
ready() {
super.ready();
this._flushProperties();
if (!this.__dataClientsInitialized) {
this._readyClients();
this._flushClients();
}
// Before ready, client notifications do not trigger _flushProperties.
// Therefore a flush is necessary here if data has been set.
Expand All @@ -1498,7 +1501,7 @@
* @protected
*/
_readyClients() {
this.__dataClientsInitialized = true;
this.__dataInitialized = true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
// or when there isn't instance props.
let options = this.__templatizeOptions;
if ((props && options.instanceProps) || !options.instanceProps) {
this._flushProperties();
this._enableProperties();
}
}
/**
Expand Down Expand Up @@ -251,7 +251,7 @@
template.__dataTemp = {};
template.__dataPending = null;
template.__dataOld = null;
template._flushProperties();
template._enableProperties();
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/property-accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
this._propertiesChanged = sinon.spy();
}
connectedCallback() {
this._flushProperties();
this._enableProperties();
}
}
XFoo.createPropertiesForAttributes();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@
BaseClass = class extends Polymer.PropertyEffects(HTMLElement) {
connectedCallback() {
this.pcSpy = sinon.spy();
this._flushProperties();
this._enableProperties();
}
_propertiesChanged(props, changedProps, oldProps) {
this.pcSpy(props, changedProps, oldProps);
Expand Down

0 comments on commit c6f9b31

Please sign in to comment.