Skip to content

Commit

Permalink
Address feedback based on review.
Browse files Browse the repository at this point in the history
* PropertyAccessors must call `_flushProperties` to enable
* Avoid tearing off oldProps (unnecessary)
* Add `addBinding` docs
* Merge notifyListeners into `setupBindings`
* Add comment re: path-bindings not being overridable
* Remove `dom` argument from `_bindTemplate`
* Rename `_stampBoundTemplate` back to `_stampTemplate`
  • Loading branch information
kevinpschaaf committed Apr 8, 2017
1 parent 03bed19 commit 6af84c4
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 137 deletions.
2 changes: 1 addition & 1 deletion lib/elements/dom-bind.html
Expand Up @@ -85,7 +85,7 @@
observer.observe(this, {childList: true});
return;
}
this.root = this._stampBoundTemplate(template);
this.root = this._stampTemplate(template);
this.$ = this.root.$;
this.__children = [];
for (let n=this.root.firstChild; n; n=n.nextSibling) {
Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/element-mixin.html
Expand Up @@ -622,7 +622,7 @@
ready() {
if (this._template) {
hostStack.beginHosting(this);
this.root = this._stampBoundTemplate(this._template);
this.root = this._stampTemplate(this._template);
hostStack.endHosting(this);
this.$ = this.root.$;
}
Expand Down
34 changes: 29 additions & 5 deletions lib/mixins/property-accessors.html
Expand Up @@ -79,7 +79,10 @@
* the standard `static get observedAttributes()`, implement `_propertiesChanged`
* on the class, and then call `MyClass.createPropertiesForAttributes()` once
* on the class to generate property accessors for each observed attribute
* prior to instancing. Any `observedAttributes` will automatically be
* prior to instancing. Last, call `this._flushProperties()` once to enable
* the accessors.
*
* Any `observedAttributes` will automatically be
* deserialized via `attributeChangedCallback` and set to the associated
* property using `dash-case`-to-`camelCase` convention.
*
Expand Down Expand Up @@ -137,6 +140,7 @@
this.__dataOld = null;
if (this.__dataProto) {
this._initializeProtoProperties(this.__dataProto);
this.__dataProto = null;
}
// Capture instance properties; these will be set into accessors
// during first flush. Don't set them here, since we want
Expand Down Expand Up @@ -168,6 +172,22 @@
}
}

/**
* Called at ready time with bag of instance properties that overwrote
* accessors when the element upgraded.
*
* The default implementation sets these properties back into the
* setter at ready time. This method is provided as an override
* point for customizing or providing more efficient initialization.
*
* @param {Object} props Bag of property values that were overwritten
* when creating property accessors.
* @protected
*/
_initializeInstanceProperties(props) {
Object.assign(this, props);
}

/**
* Ensures the element has the given attribute. If it does not,
* assigns the given value to the attribute.
Expand Down Expand Up @@ -444,7 +464,7 @@
* @protected
*/
_invalidateProperties() {
if (!this.__dataInvalid) {
if (!this.__dataInvalid && this.__dataInitialized) {
this.__dataInvalid = true;
microtask.run(() => {
if (this.__dataInvalid) {
Expand All @@ -460,17 +480,20 @@
* pending changes (and old values recorded when pending changes were
* set), and resets the pending set of changes.
*
* Note that this method must be called once to enable the property
* accessors system. For elements, generally `connectedCallback`
* is a normal spot to do so.
*
* @protected
*/
_flushProperties() {
if (!this.__dataInitialized) {
this.ready()
} else if (this.__dataPending) {
let oldProps = this.__dataOld;
let changedProps = this.__dataPending;
this.__dataPending = null;
this.__dataCounter++;
this._propertiesChanged(this.__data, changedProps, oldProps);
this._propertiesChanged(this.__data, changedProps, this.__dataOld);
this.__dataCounter--;
}
}
Expand All @@ -493,7 +516,8 @@
// Update instance properties that shadowed proto accessors; these take
// priority over any defaults set in constructor or attributeChangedCallback
if (this.__dataInstanceProps) {
Object.assign(this, this.__dataInstanceProps);
this._initializeInstanceProperties(this.__dataInstanceProps);
this.__dataInstanceProps = null;
}
this.__dataInitialized = true;
// Run normal flush
Expand Down

0 comments on commit 6af84c4

Please sign in to comment.