Skip to content

Commit

Permalink
lazily create effect objects so we can more easily abort processing.
Browse files Browse the repository at this point in the history
avoid forEach
  • Loading branch information
Steven Orvell committed Nov 3, 2015
1 parent a2376b6 commit 66df196
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
23 changes: 14 additions & 9 deletions src/micro/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@

Polymer.Base._addFeature({

_prepAttributes: function() {
this._aggregatedAttributes = {};
},

_addHostAttributes: function(attributes) {
if (!this._aggregatedAttributes) {
this._aggregatedAttributes = {};
}
if (attributes) {
this.mixin(this._aggregatedAttributes, attributes);
}
},

_marshalHostAttributes: function() {
this._applyAttributes(this, this._aggregatedAttributes);
if (this._aggregatedAttributes) {
this._applyAttributes(this, this._aggregatedAttributes);
}
},

/* apply attributes to node but avoid overriding existing values */
Expand All @@ -83,8 +84,9 @@
if (!this.hasAttribute(n) && (n !== 'class')) {
var v = attr$[n];
this.serializeValueToAttribute(v, n, this);
// TODO(sorvell): this should not be in micro layer.
// if necessary, add this value to configuration...
if (!this._clientsReady && this._propertyInfo[n] &&
if (!this._clientsReadied && this._propertyInfo[n] &&
(this._config[n] === undefined)) {
this._config[n] = v;
}
Expand Down Expand Up @@ -161,9 +163,12 @@
// this._warn(this._logf('serializeValueToAttribute',
// 'serializing long attribute values can lead to poor performance', this));
// }
(node || this)
[str === undefined ? 'removeAttribute' : 'setAttribute']
(attribute, str);
node = node || this;
if (str === undefined) {
node.removeAttribute(attribute);
} else {
node.setAttribute(attribute, str);
}
},

/**
Expand Down
43 changes: 21 additions & 22 deletions src/micro/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@

_flattenBehaviorsList: function(behaviors) {
var flat = [];
behaviors.forEach(function(b) {
for (var i=0; i < behaviors.length; i++) {
var b = behaviors[i];
if (b instanceof Array) {
flat = flat.concat(this._flattenBehaviorsList(b));
}
Expand All @@ -89,32 +90,17 @@
} else {
this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for missing or 404 import'));
}
}, this);
}
return flat;
},

_mixinBehavior: function(b) {
Object.getOwnPropertyNames(b).forEach(function(n) {
switch (n) {
case 'hostAttributes':
case 'registered':
case 'properties':
case 'observers':
case 'listeners':
case 'created':
case 'attached':
case 'detached':
case 'attributeChanged':
case 'configure':
case 'ready':
break;
default:
if (!this.hasOwnProperty(n)) {
this.copyOwnProperty(n, b, this);
}
break;
var n$ = Object.getOwnPropertyNames(b);
for (var i=0, n; (i<n$.length) && (n=n$[i]); i++) {
if (!Polymer.Base._behaviorMethods[n] && !this.hasOwnProperty(n)) {
this.copyOwnProperty(n, b, this);
}
}, this);
}
},

_prepBehaviors: function() {
Expand Down Expand Up @@ -155,4 +141,17 @@

});

Polymer.Base._behaviorMethods = {
hostAttributes: true,
registered: true,
properties: true,
observers: true,
listeners: true,
created: true,
attached: true,
detached: true,
attributeChanged: true,
ready: true
}

</script>
9 changes: 6 additions & 3 deletions src/micro/properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@
getPropertyInfo: function(property) {
var info = this._getPropertyInfo(property, this.properties);
if (!info) {
this.behaviors.some(function(b) {
return info = this._getPropertyInfo(property, b.properties);
}, this);
for (var i=0; i < this.behaviors.length; i++) {
info = this._getPropertyInfo(property, this.behaviors[i].properties);
if (info) {
return info;
}
};
}
return info || Polymer.nob;
},
Expand Down
4 changes: 2 additions & 2 deletions src/standard/x-styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// if it has any _stylePropertyNames
this._ownStylePropertyNames = this._styles ?
propertyUtils.decorateStyles(this._styles) :
[];
null;
},

/**
Expand All @@ -40,7 +40,7 @@
* (analogous to setting `style`) and then calling `updateStyles()`.
*
*/
customStyle: {},
customStyle: null,

// here we have an instance time spot to put custom property data
_setupStyleProperties: function() {
Expand Down

0 comments on commit 66df196

Please sign in to comment.