Skip to content

Commit

Permalink
rename host functions
Browse files Browse the repository at this point in the history
fix typos
afterFirstRender is now raf+setTimeout
dom-repeat: remove cruft
  • Loading branch information
Steven Orvell committed Nov 5, 2015
1 parent e0fbfbe commit d82840b
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 89 deletions.
6 changes: 3 additions & 3 deletions polymer-mini.html
Expand Up @@ -41,16 +41,16 @@
},

_initFeatures: function() {
this._calcHost();
this._registerHost();
if (this._template) {
// manage local dom
this._poolContent();
// host stack
this._beginHost();
this._beginHosting();
// instantiate template
this._stampTemplate();
// host stack
this._popHost();
this._endHosting();
}
// install host attributes
this._marshalHostAttributes();
Expand Down
6 changes: 3 additions & 3 deletions polymer.html
Expand Up @@ -63,16 +63,16 @@
this._setupStyleProperties();
// setup debouncers
this._setupDebouncers();
this._calcHost();
this._registerHost();
if (this._template) {
// manage local dom
this._poolContent();
// host stack
this._beginHost();
this._beginHosting();
// instantiate template
this._stampTemplate();
// host stack
this._popHost();
this._endHosting();
// concretize template references
this._marshalAnnotationReferences();
}
Expand Down
17 changes: 13 additions & 4 deletions src/lib/bind/accessors.html
Expand Up @@ -248,13 +248,22 @@
// Property listeners:
// <node>.on.<property>-changed: <path]> = e.detail.value
//console.log('[_setupBindListener]: [%s][%s] listening for [%s][%s-changed]', this.localName, info.path, info.id || info.index, info.property);
this._addNotifyListener(inst._nodes[info.index], inst, info);
//
// TODO(sorvell): fix templatizer to support this before uncommenting
// Optimization: only add bind listeners if the bound property is notifying...
var node = inst._nodes[info.index];
//var p = node._propertyInfo && node._propertyInfo[info.property];
//if (node._prepParentProperties || !node._propertyInfo || (p && p.notify)) {
this._addNotifyListener(node, inst, info.event, info.changedFn);
//}
};
},

_addNotifyListener: function(element, context, info) {
element.addEventListener(info.event, function(e) {
return context._notifyListener(info.changedFn, e);
// TODO(sorvell): note, adding these synchronously may impact performance,
// measure and consider if we can defer until after first paint in some cases at least.
_addNotifyListener: function(element, context, event, changedFn) {
element.addEventListener(event, function(e) {
return context._notifyListener(changedFn, e);
});
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/lib/collection.html
Expand Up @@ -131,14 +131,14 @@
// corresponding to the added/removed items
_applySplices: function(splices) {
// Dedupe added and removed keys to a final added/removed map
var keyMap = {}, key, i;
var keyMap = {}, key;
for (var i=0, s; (i<splices.length) && (s=splices[i]); i++) {
s.addedKeys = [];
for (j=0; j<s.removed.length; j++) {
for (var j=0; j<s.removed.length; j++) {
key = this.getKey(s.removed[j]);
keyMap[key] = keyMap[key] ? null : -1;
}
for (j=0; j<s.addedCount; j++) {
for (var j=0; j<s.addedCount; j++) {
var item = this.userArray[s.index + j];
key = this.getKey(item);
key = (key === undefined) ? this.add(item) : key;
Expand Down
7 changes: 1 addition & 6 deletions src/lib/dom-api.html
Expand Up @@ -931,12 +931,7 @@
// actual children will be treated as the rendered state once lightChildren
// is populated.
if (!node._lightChildren) {
var c$ = [];
var n = node.firstChild;
while (n) {
c$.push(n);
n = n.nextSibling;
}
var c$ = arrayCopyChildNodes(node);
for (var i=0, l=c$.length, child; (i<l) && (child=c$[i]); i++) {
child._lightParent = child._lightParent || node;
}
Expand Down
9 changes: 2 additions & 7 deletions src/lib/render-status.html
Expand Up @@ -62,14 +62,9 @@
},

_flushAfterFirstRender: function() {
// we want to defer flush until just after the next paint.
requestAnimationFrame(function() {
var self = Polymer.RenderStatus;
// if already ready, wait 2 frames to ensure async
if (self._ready) {
requestAnimationFrame(self.__flushAfterFirstRender);
} else {
self.__flushAfterFirstRender();
}
setTimeout(Polymer.RenderStatus.__flushAfterFirstRender);
});
},

Expand Down
2 changes: 1 addition & 1 deletion src/lib/style-util.html
Expand Up @@ -145,7 +145,7 @@

resolveCss: Polymer.ResolveUrl.resolveCss,
parser: Polymer.CssParse,
ruleTypes: Polymer.CssParse.types,
ruleTypes: Polymer.CssParse.types

};

Expand Down
21 changes: 9 additions & 12 deletions src/lib/template/dom-repeat.html
Expand Up @@ -368,15 +368,16 @@
}
}
}
// capture reference for use in filter/sort fn's
var self = this;
// Apply user filter to keys
if (this._filterFn) {
keys = keys.filter(function(a) {
return this._filterFn(c.getItem(a));
}, this);
return self._filterFn(c.getItem(a));
});
}
// Apply user sort to keys
if (this._sortFn) {
var self = this;
keys.sort(function(a, b) {
return self._sortFn(c.getItem(a), c.getItem(b));
});
Expand Down Expand Up @@ -416,9 +417,6 @@
var instances = this._instances;
var keyMap = {};
var pool = [];
var self = this;
var sortFn = this._sortFn ||
function(a, b) { return self._keySort(a, b); };
// Dedupe added and removed keys to a final added/removed map
for (var i=0, s; (i<splices.length) && (s=splices[i]); i++) {
for (var j=0; j<s.removed.length; j++) {
Expand Down Expand Up @@ -456,16 +454,17 @@
}
}
}
// capture reference for use in filter/sort fn's
var self = this;
// Add instances for added keys
if (addedKeys.length) {
// Filter added keys
if (this._filterFn) {
addedKeys = addedKeys.filter(function(a) {
return this._filterFn(c.getItem(a));
}, this);
return self._filterFn(c.getItem(a));
});
}
// Sort added keys
var self = this;
addedKeys.sort(function(a, b) {
return self._sortFn(c.getItem(a), c.getItem(b));
});
Expand All @@ -482,13 +481,11 @@
var item = c.getItem(key);
var end = this._instances.length - 1;
var idx = -1;
var sortFn = this._sortFn ||
function(a, b) { return self._keySort(a, b); };
// Binary search for insertion point
while (start <= end) {
var mid = (start + end) >> 1;
var midKey = this._instances[mid].__key__;
var cmp = sortFn(c.getItem(midKey), item);
var cmp = this._sortFn(c.getItem(midKey), item);
if (cmp < 0) {
start = mid + 1;
} else if (cmp > 0) {
Expand Down
29 changes: 5 additions & 24 deletions src/lib/template/templatizer.html
Expand Up @@ -248,16 +248,16 @@
Polymer.Bind._createAccessors(proto, parentProp, effects);
}
}
// capture this reference for use below
var self = this;
// Instance setup
if (template != this) {
Polymer.Bind.prepareInstance(template);
var self = this;
template._forwardParentProp = function(source, value) {
self._forwardParentProp(source, value);
}
}
this._extendTemplate(template, proto);
var self = this;
template._pathEffector = function(path, value, fromAbove) {
return self._pathEffectorImpl(path, value, fromAbove);
}
Expand Down Expand Up @@ -332,12 +332,12 @@
_constructorImpl: function(model, host) {
this._rootDataHost = host._getRootDataHost();
this._setupConfigure(model);
this._calcHost(host);
this._beginHost();
this._registerHost(host);
this._beginHosting();
this.root = this.instanceTemplate(this._template);
this.root.__noContent = !this._notes._hasContent;
this.root.__styleScoped = true;
this._popHost();
this._endHosting();
this._marshalAnnotatedNodes();
this._marshalInstanceEffects();
this._marshalAnnotatedListeners();
Expand Down Expand Up @@ -450,25 +450,6 @@
}
}

// TODO(sorvell): note, using the template as host is ~5-10% faster if
// elements have no default values.
// _constructorImpl: function(model, host) {
// this._setupConfigure(model);
// host._beginHost();
// this.root = this.instanceTemplate(this._template);
// host._popHost();
// this._marshalTemplateContent();
// this._marshalAnnotatedNodes();
// this._marshalInstanceEffects();
// this._marshalAnnotatedListeners();
// this._ready();
// },

// stamp: function(model) {
// return new this.ctor(model, this.dataHost);
// }


};

</script>
5 changes: 4 additions & 1 deletion src/micro/attributes.html
Expand Up @@ -60,6 +60,7 @@

Polymer.Base._addFeature({

// prototype time
_addHostAttributes: function(attributes) {
if (!this._aggregatedAttributes) {
this._aggregatedAttributes = {};
Expand All @@ -69,6 +70,7 @@
}
},

// instance time
_marshalHostAttributes: function() {
if (this._aggregatedAttributes) {
this._applyAttributes(this, this._aggregatedAttributes);
Expand All @@ -88,7 +90,7 @@
// if necessary, add this value to configuration...
if (!this._clientsReadied && this._propertyInfo[n] &&
(this._config[n] === undefined)) {
this._config[n] = v;
this._configValue(n, v);
}
}
}
Expand All @@ -114,6 +116,7 @@
if (!this._serializing) {
var property = property || Polymer.CaseMap.dashToCamelCase(attribute);
// fallback to property lookup
// TODO(sorvell): check for _propertyInfo existence because of dom-bind
info = info || (this._propertyInfo && this._propertyInfo[property]);
if (info && !info.readOnly) {
var v = this.getAttribute(attribute);
Expand Down
7 changes: 5 additions & 2 deletions src/micro/behaviors.html
Expand Up @@ -97,7 +97,7 @@
_mixinBehavior: function(b) {
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)) {
if (!Polymer.Base._behaviorProperties[n] && !this.hasOwnProperty(n)) {
this.copyOwnProperty(n, b, this);
}
}
Expand Down Expand Up @@ -141,7 +141,10 @@

});

Polymer.Base._behaviorMethods = {
// special properties on behaviors are not mixed in and are instead
// either processed specially (e.g. listeners, properties) or available
// for calling via doBehavior (e.g. created, ready)
Polymer.Base._behaviorProperties = {
hostAttributes: true,
registered: true,
properties: true,
Expand Down
8 changes: 7 additions & 1 deletion src/micro/properties.html
Expand Up @@ -152,7 +152,7 @@
// optimization: avoid info'ing properties that are protected and
// not read only since they are not needed for attributes or
// configuration.
if (i.indexOf('_') === 0 && !s.readOnly) {
if (i[0] === '_' && !s.readOnly) {
continue;
}
if (!target[i]) {
Expand All @@ -165,6 +165,12 @@
if (!t.readOnly) {
t.readOnly = s.readOnly;
}
if (!t.notify) {
t.notify = s.notify;
}
if (!t.readOnly) {
t.readOnly = s.readOnly;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/mini/ready.html
Expand Up @@ -62,7 +62,7 @@
// any bindings for the element. Only elements originally
// stamped from Polymer templates have a dataHost, and this
// never changes
_calcHost: function(host) {
_registerHost: function(host) {
// NOTE: The `dataHost` of an element never changes.
this.dataHost = host = host ||
Polymer.Base._hostStack[Polymer.Base._hostStack.length-1];
Expand All @@ -73,14 +73,14 @@

// establish this element as the current hosting element (allows
// any elements we stamp to easily set host to us).
_beginHost: function() {
_beginHosting: function() {
Polymer.Base._hostStack.push(this);
if (!this._clients) {
this._clients = [];
}
},

_popHost: function() {
_endHosting: function() {
// this element is no longer the current hosting element
Polymer.Base._hostStack.pop();
},
Expand Down
1 change: 1 addition & 0 deletions src/mini/shady.html
Expand Up @@ -55,6 +55,7 @@
_createLocalRoot: function() {
this.shadyRoot = this.root;
this.shadyRoot._distributionClean = false;
this.shadyRoot._hasDistributed = false;
this.shadyRoot._isShadyRoot = true;
this.shadyRoot._dirtyRoots = [];
// capture insertion point list
Expand Down
12 changes: 6 additions & 6 deletions src/standard/annotations.html
Expand Up @@ -187,8 +187,8 @@
for (var k=0, p$=b.parts, p; (k<p$.length) && (p=p$[k]); k++) {
if (p.signature) {
var args = p.signature.args;
for (var k=0; k<args.length; k++) {
pp[args[k].model] = true;
for (var kk=0; kk<args.length; kk++) {
pp[args[kk].model] = true;
}
} else {
pp[p.model] = true;
Expand Down Expand Up @@ -291,10 +291,10 @@

// concretize `_nodes` map (from anonymous annotations)
_marshalAnnotatedNodes: function() {
if (this._nodes && this._nodes.length) {
var r = new Array(this._nodes.length);
for (var i=0; i < this._nodes.length; i++) {
r[i] = this._findAnnotatedNode(this.root, this._nodes[i]);
if (this._notes && this._notes.length) {
var r = new Array(this._notes.length);
for (var i=0; i < this._notes.length; i++) {
r[i] = this._findAnnotatedNode(this.root, this._notes[i]);
}
this._nodes = r;
}
Expand Down
5 changes: 0 additions & 5 deletions src/standard/configure.html
Expand Up @@ -124,11 +124,6 @@

_mixinConfigure: function(a, b) {
for (var prop in b) {
//if (!this.getPropertyInfo(prop).readOnly) {
// TODO(sorvell): tempatized things don't have _propertyInfo atm
// so fallback to property lookup.
// var info = this._propertyInfo && this._propertyInfo[prop] ||
// this.getPropertyInfo(prop);
var info = this._propertyInfo[prop];
if (!info || !info.readOnly) {
a[prop] = b[prop];
Expand Down

0 comments on commit d82840b

Please sign in to comment.