Skip to content

Commit d82840b

Browse files
author
Steven Orvell
committed
rename host functions
fix typos afterFirstRender is now raf+setTimeout dom-repeat: remove cruft
1 parent e0fbfbe commit d82840b

19 files changed

+72
-89
lines changed

polymer-mini.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@
4141
},
4242

4343
_initFeatures: function() {
44-
this._calcHost();
44+
this._registerHost();
4545
if (this._template) {
4646
// manage local dom
4747
this._poolContent();
4848
// host stack
49-
this._beginHost();
49+
this._beginHosting();
5050
// instantiate template
5151
this._stampTemplate();
5252
// host stack
53-
this._popHost();
53+
this._endHosting();
5454
}
5555
// install host attributes
5656
this._marshalHostAttributes();

polymer.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@
6363
this._setupStyleProperties();
6464
// setup debouncers
6565
this._setupDebouncers();
66-
this._calcHost();
66+
this._registerHost();
6767
if (this._template) {
6868
// manage local dom
6969
this._poolContent();
7070
// host stack
71-
this._beginHost();
71+
this._beginHosting();
7272
// instantiate template
7373
this._stampTemplate();
7474
// host stack
75-
this._popHost();
75+
this._endHosting();
7676
// concretize template references
7777
this._marshalAnnotationReferences();
7878
}

src/lib/bind/accessors.html

+13-4
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,22 @@
248248
// Property listeners:
249249
// <node>.on.<property>-changed: <path]> = e.detail.value
250250
//console.log('[_setupBindListener]: [%s][%s] listening for [%s][%s-changed]', this.localName, info.path, info.id || info.index, info.property);
251-
this._addNotifyListener(inst._nodes[info.index], inst, info);
251+
//
252+
// TODO(sorvell): fix templatizer to support this before uncommenting
253+
// Optimization: only add bind listeners if the bound property is notifying...
254+
var node = inst._nodes[info.index];
255+
//var p = node._propertyInfo && node._propertyInfo[info.property];
256+
//if (node._prepParentProperties || !node._propertyInfo || (p && p.notify)) {
257+
this._addNotifyListener(node, inst, info.event, info.changedFn);
258+
//}
252259
};
253260
},
254261

255-
_addNotifyListener: function(element, context, info) {
256-
element.addEventListener(info.event, function(e) {
257-
return context._notifyListener(info.changedFn, e);
262+
// TODO(sorvell): note, adding these synchronously may impact performance,
263+
// measure and consider if we can defer until after first paint in some cases at least.
264+
_addNotifyListener: function(element, context, event, changedFn) {
265+
element.addEventListener(event, function(e) {
266+
return context._notifyListener(changedFn, e);
258267
});
259268
}
260269
};

src/lib/collection.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@
131131
// corresponding to the added/removed items
132132
_applySplices: function(splices) {
133133
// Dedupe added and removed keys to a final added/removed map
134-
var keyMap = {}, key, i;
134+
var keyMap = {}, key;
135135
for (var i=0, s; (i<splices.length) && (s=splices[i]); i++) {
136136
s.addedKeys = [];
137-
for (j=0; j<s.removed.length; j++) {
137+
for (var j=0; j<s.removed.length; j++) {
138138
key = this.getKey(s.removed[j]);
139139
keyMap[key] = keyMap[key] ? null : -1;
140140
}
141-
for (j=0; j<s.addedCount; j++) {
141+
for (var j=0; j<s.addedCount; j++) {
142142
var item = this.userArray[s.index + j];
143143
key = this.getKey(item);
144144
key = (key === undefined) ? this.add(item) : key;

src/lib/dom-api.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,7 @@
931931
// actual children will be treated as the rendered state once lightChildren
932932
// is populated.
933933
if (!node._lightChildren) {
934-
var c$ = [];
935-
var n = node.firstChild;
936-
while (n) {
937-
c$.push(n);
938-
n = n.nextSibling;
939-
}
934+
var c$ = arrayCopyChildNodes(node);
940935
for (var i=0, l=c$.length, child; (i<l) && (child=c$[i]); i++) {
941936
child._lightParent = child._lightParent || node;
942937
}

src/lib/render-status.html

+2-7
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,9 @@
6262
},
6363

6464
_flushAfterFirstRender: function() {
65+
// we want to defer flush until just after the next paint.
6566
requestAnimationFrame(function() {
66-
var self = Polymer.RenderStatus;
67-
// if already ready, wait 2 frames to ensure async
68-
if (self._ready) {
69-
requestAnimationFrame(self.__flushAfterFirstRender);
70-
} else {
71-
self.__flushAfterFirstRender();
72-
}
67+
setTimeout(Polymer.RenderStatus.__flushAfterFirstRender);
7368
});
7469
},
7570

src/lib/style-util.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145

146146
resolveCss: Polymer.ResolveUrl.resolveCss,
147147
parser: Polymer.CssParse,
148-
ruleTypes: Polymer.CssParse.types,
148+
ruleTypes: Polymer.CssParse.types
149149

150150
};
151151

src/lib/template/dom-repeat.html

+9-12
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,16 @@
368368
}
369369
}
370370
}
371+
// capture reference for use in filter/sort fn's
372+
var self = this;
371373
// Apply user filter to keys
372374
if (this._filterFn) {
373375
keys = keys.filter(function(a) {
374-
return this._filterFn(c.getItem(a));
375-
}, this);
376+
return self._filterFn(c.getItem(a));
377+
});
376378
}
377379
// Apply user sort to keys
378380
if (this._sortFn) {
379-
var self = this;
380381
keys.sort(function(a, b) {
381382
return self._sortFn(c.getItem(a), c.getItem(b));
382383
});
@@ -416,9 +417,6 @@
416417
var instances = this._instances;
417418
var keyMap = {};
418419
var pool = [];
419-
var self = this;
420-
var sortFn = this._sortFn ||
421-
function(a, b) { return self._keySort(a, b); };
422420
// Dedupe added and removed keys to a final added/removed map
423421
for (var i=0, s; (i<splices.length) && (s=splices[i]); i++) {
424422
for (var j=0; j<s.removed.length; j++) {
@@ -456,16 +454,17 @@
456454
}
457455
}
458456
}
457+
// capture reference for use in filter/sort fn's
458+
var self = this;
459459
// Add instances for added keys
460460
if (addedKeys.length) {
461461
// Filter added keys
462462
if (this._filterFn) {
463463
addedKeys = addedKeys.filter(function(a) {
464-
return this._filterFn(c.getItem(a));
465-
}, this);
464+
return self._filterFn(c.getItem(a));
465+
});
466466
}
467467
// Sort added keys
468-
var self = this;
469468
addedKeys.sort(function(a, b) {
470469
return self._sortFn(c.getItem(a), c.getItem(b));
471470
});
@@ -482,13 +481,11 @@
482481
var item = c.getItem(key);
483482
var end = this._instances.length - 1;
484483
var idx = -1;
485-
var sortFn = this._sortFn ||
486-
function(a, b) { return self._keySort(a, b); };
487484
// Binary search for insertion point
488485
while (start <= end) {
489486
var mid = (start + end) >> 1;
490487
var midKey = this._instances[mid].__key__;
491-
var cmp = sortFn(c.getItem(midKey), item);
488+
var cmp = this._sortFn(c.getItem(midKey), item);
492489
if (cmp < 0) {
493490
start = mid + 1;
494491
} else if (cmp > 0) {

src/lib/template/templatizer.html

+5-24
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,16 @@
248248
Polymer.Bind._createAccessors(proto, parentProp, effects);
249249
}
250250
}
251+
// capture this reference for use below
252+
var self = this;
251253
// Instance setup
252254
if (template != this) {
253255
Polymer.Bind.prepareInstance(template);
254-
var self = this;
255256
template._forwardParentProp = function(source, value) {
256257
self._forwardParentProp(source, value);
257258
}
258259
}
259260
this._extendTemplate(template, proto);
260-
var self = this;
261261
template._pathEffector = function(path, value, fromAbove) {
262262
return self._pathEffectorImpl(path, value, fromAbove);
263263
}
@@ -332,12 +332,12 @@
332332
_constructorImpl: function(model, host) {
333333
this._rootDataHost = host._getRootDataHost();
334334
this._setupConfigure(model);
335-
this._calcHost(host);
336-
this._beginHost();
335+
this._registerHost(host);
336+
this._beginHosting();
337337
this.root = this.instanceTemplate(this._template);
338338
this.root.__noContent = !this._notes._hasContent;
339339
this.root.__styleScoped = true;
340-
this._popHost();
340+
this._endHosting();
341341
this._marshalAnnotatedNodes();
342342
this._marshalInstanceEffects();
343343
this._marshalAnnotatedListeners();
@@ -450,25 +450,6 @@
450450
}
451451
}
452452

453-
// TODO(sorvell): note, using the template as host is ~5-10% faster if
454-
// elements have no default values.
455-
// _constructorImpl: function(model, host) {
456-
// this._setupConfigure(model);
457-
// host._beginHost();
458-
// this.root = this.instanceTemplate(this._template);
459-
// host._popHost();
460-
// this._marshalTemplateContent();
461-
// this._marshalAnnotatedNodes();
462-
// this._marshalInstanceEffects();
463-
// this._marshalAnnotatedListeners();
464-
// this._ready();
465-
// },
466-
467-
// stamp: function(model) {
468-
// return new this.ctor(model, this.dataHost);
469-
// }
470-
471-
472453
};
473454

474455
</script>

src/micro/attributes.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
Polymer.Base._addFeature({
6262

63+
// prototype time
6364
_addHostAttributes: function(attributes) {
6465
if (!this._aggregatedAttributes) {
6566
this._aggregatedAttributes = {};
@@ -69,6 +70,7 @@
6970
}
7071
},
7172

73+
// instance time
7274
_marshalHostAttributes: function() {
7375
if (this._aggregatedAttributes) {
7476
this._applyAttributes(this, this._aggregatedAttributes);
@@ -88,7 +90,7 @@
8890
// if necessary, add this value to configuration...
8991
if (!this._clientsReadied && this._propertyInfo[n] &&
9092
(this._config[n] === undefined)) {
91-
this._config[n] = v;
93+
this._configValue(n, v);
9294
}
9395
}
9496
}
@@ -114,6 +116,7 @@
114116
if (!this._serializing) {
115117
var property = property || Polymer.CaseMap.dashToCamelCase(attribute);
116118
// fallback to property lookup
119+
// TODO(sorvell): check for _propertyInfo existence because of dom-bind
117120
info = info || (this._propertyInfo && this._propertyInfo[property]);
118121
if (info && !info.readOnly) {
119122
var v = this.getAttribute(attribute);

src/micro/behaviors.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
_mixinBehavior: function(b) {
9898
var n$ = Object.getOwnPropertyNames(b);
9999
for (var i=0, n; (i<n$.length) && (n=n$[i]); i++) {
100-
if (!Polymer.Base._behaviorMethods[n] && !this.hasOwnProperty(n)) {
100+
if (!Polymer.Base._behaviorProperties[n] && !this.hasOwnProperty(n)) {
101101
this.copyOwnProperty(n, b, this);
102102
}
103103
}
@@ -141,7 +141,10 @@
141141

142142
});
143143

144-
Polymer.Base._behaviorMethods = {
144+
// special properties on behaviors are not mixed in and are instead
145+
// either processed specially (e.g. listeners, properties) or available
146+
// for calling via doBehavior (e.g. created, ready)
147+
Polymer.Base._behaviorProperties = {
145148
hostAttributes: true,
146149
registered: true,
147150
properties: true,

src/micro/properties.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
// optimization: avoid info'ing properties that are protected and
153153
// not read only since they are not needed for attributes or
154154
// configuration.
155-
if (i.indexOf('_') === 0 && !s.readOnly) {
155+
if (i[0] === '_' && !s.readOnly) {
156156
continue;
157157
}
158158
if (!target[i]) {
@@ -165,6 +165,12 @@
165165
if (!t.readOnly) {
166166
t.readOnly = s.readOnly;
167167
}
168+
if (!t.notify) {
169+
t.notify = s.notify;
170+
}
171+
if (!t.readOnly) {
172+
t.readOnly = s.readOnly;
173+
}
168174
}
169175
}
170176
}

src/mini/ready.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
// any bindings for the element. Only elements originally
6363
// stamped from Polymer templates have a dataHost, and this
6464
// never changes
65-
_calcHost: function(host) {
65+
_registerHost: function(host) {
6666
// NOTE: The `dataHost` of an element never changes.
6767
this.dataHost = host = host ||
6868
Polymer.Base._hostStack[Polymer.Base._hostStack.length-1];
@@ -73,14 +73,14 @@
7373

7474
// establish this element as the current hosting element (allows
7575
// any elements we stamp to easily set host to us).
76-
_beginHost: function() {
76+
_beginHosting: function() {
7777
Polymer.Base._hostStack.push(this);
7878
if (!this._clients) {
7979
this._clients = [];
8080
}
8181
},
8282

83-
_popHost: function() {
83+
_endHosting: function() {
8484
// this element is no longer the current hosting element
8585
Polymer.Base._hostStack.pop();
8686
},

src/mini/shady.html

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
_createLocalRoot: function() {
5656
this.shadyRoot = this.root;
5757
this.shadyRoot._distributionClean = false;
58+
this.shadyRoot._hasDistributed = false;
5859
this.shadyRoot._isShadyRoot = true;
5960
this.shadyRoot._dirtyRoots = [];
6061
// capture insertion point list

src/standard/annotations.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@
187187
for (var k=0, p$=b.parts, p; (k<p$.length) && (p=p$[k]); k++) {
188188
if (p.signature) {
189189
var args = p.signature.args;
190-
for (var k=0; k<args.length; k++) {
191-
pp[args[k].model] = true;
190+
for (var kk=0; kk<args.length; kk++) {
191+
pp[args[kk].model] = true;
192192
}
193193
} else {
194194
pp[p.model] = true;
@@ -291,10 +291,10 @@
291291

292292
// concretize `_nodes` map (from anonymous annotations)
293293
_marshalAnnotatedNodes: function() {
294-
if (this._nodes && this._nodes.length) {
295-
var r = new Array(this._nodes.length);
296-
for (var i=0; i < this._nodes.length; i++) {
297-
r[i] = this._findAnnotatedNode(this.root, this._nodes[i]);
294+
if (this._notes && this._notes.length) {
295+
var r = new Array(this._notes.length);
296+
for (var i=0; i < this._notes.length; i++) {
297+
r[i] = this._findAnnotatedNode(this.root, this._notes[i]);
298298
}
299299
this._nodes = r;
300300
}

src/standard/configure.html

-5
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@
124124

125125
_mixinConfigure: function(a, b) {
126126
for (var prop in b) {
127-
//if (!this.getPropertyInfo(prop).readOnly) {
128-
// TODO(sorvell): tempatized things don't have _propertyInfo atm
129-
// so fallback to property lookup.
130-
// var info = this._propertyInfo && this._propertyInfo[prop] ||
131-
// this.getPropertyInfo(prop);
132127
var info = this._propertyInfo[prop];
133128
if (!info || !info.readOnly) {
134129
a[prop] = b[prop];

0 commit comments

Comments
 (0)