Skip to content

Commit

Permalink
Make propagation of attribute changes at configure time more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Aug 4, 2015
1 parent 7c83df5 commit b269c1d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/lib/base.html
Expand Up @@ -49,10 +49,14 @@

// reserved for canonical behavior
attributeChangedCallback: function(name) {
this._setAttributeToProperty(this, name); // abstract
this._attributeChangedImpl(name); // abstract
this._doBehavior('attributeChanged', arguments); // abstract
},

_attributeChangedImpl: function(name) {
this._setAttributeToProperty(this, name);
},

/**
* Copies own properties (including accessor descriptors) from a source
* object to a target object.
Expand Down
5 changes: 5 additions & 0 deletions src/standard/configure.html
Expand Up @@ -60,6 +60,11 @@
this._takeAttributesToModel(this._config);
},

_attributeChangedImpl: function(name) {
var model = this._readied ? this : this._config;
this._setAttributeToProperty(model, name);
},

// at configure time values are stored in _config
_configValue: function(name, value) {
this._config[name] = value;
Expand Down
25 changes: 24 additions & 1 deletion test/unit/attributes-elements.html
Expand Up @@ -51,8 +51,28 @@
type: String,
value: 'default',
readOnly: true
},
prop: {
value: 'prop',
observer: 'propChanged'
},

attr1: {
observer: 'attr1Changed'
}
},

propChangedCount: 0,
attr1ChangedCount: 0,

propChanged: function(prop) {
this.propChangedCount++;
},

attr1Changed: function(prop) {
this.attr1ChangedCount++;
}

});
</script>

Expand Down Expand Up @@ -114,11 +134,14 @@

<dom-module id="x-compose">
<template>
<x-basic id="basic" class="should-not-override"></x-basic>
<x-basic id="basic" prop="{{attr1}}" attr1$="{{attr1}}" class="should-not-override"></x-basic>
</template>
</dom-module>
<script>
Polymer({
hostAttributes: {
attr1: 'compose'
},
is: 'x-compose'
});
</script>
6 changes: 5 additions & 1 deletion test/unit/attributes.html
Expand Up @@ -267,7 +267,7 @@
});

test('hostAttributes set correctly in composed element', function() {
assert.strictEqual(compose.$.basic.getAttribute('attr1'), 'this is attr 1');
assert.strictEqual(compose.$.basic.getAttribute('attr1'), 'compose');
assert.strictEqual(compose.$.basic.getAttribute('attr2'), '42');
assert.strictEqual(compose.$.basic.getAttribute('aria-role'), 'button');
assert.strictEqual(compose.$.basic.getAttribute('title'), 'awesome');
Expand All @@ -280,6 +280,10 @@
assert.notOk(compose.$.basic.classList.contains('bar'));
assert.notOk(compose.$.basic.classList.contains('baz'));
assert(compose.$.basic.classList.contains('should-not-override'));
// applied to property with effect
assert.strictEqual(compose.$.basic.prop, 'compose');
assert.equal(compose.$.basic.propChangedCount, 1);
assert.equal(compose.$.basic.attr1ChangedCount, 1);
});

});
Expand Down

0 comments on commit b269c1d

Please sign in to comment.