Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.8 fix xif polyfill #1469

Merged
merged 10 commits into from
Apr 30, 2015
13 changes: 8 additions & 5 deletions src/lib/polymer-bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
-->
<script>

// until ES6 modules become standard, we follow Occam and simply stake out
// until ES6 modules become standard, we follow Occam and simply stake out
// a global namespace

// Polymer is a Function, but of course this is also an Object, so we
// Polymer is a Function, but of course this is also an Object, so we
// hang various other objects off of Polymer.*
(function() {
var userPolymer = window.Polymer;

window.Polymer = function(prototype) {
var ctor = desugar(prototype);
// Polymer.Base is now chained to ctor.prototype, and for IE10 compat
// this may have resulted in a new prototype being created
prototype = ctor.prototype;
// native Custom Elements treats 'undefined' extends property
// as valued, the property must not exist to be ignored
var options = {
prototype: ctor.prototype
prototype: prototype
};
if (prototype.extends) {
options.extends = prototype.extends;
Expand Down Expand Up @@ -53,7 +56,7 @@
// Raw usage
[ctor =] Polymer.Class(prototype);
document.registerElement(name, ctor);

// Simplified usage
[ctor = ] Polymer(prototype);
*/
Expand Down
70 changes: 51 additions & 19 deletions src/lib/template/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,25 @@

Polymer.Templatizer = {

properties: {
_hideTemplateChildren: {
observer: '_hideTemplateChildrenChanged'
}
},

// Intentionally static object
_templatizerStatic: {
count: 0,
callbacks: {},
debouncer: null
},

created: function() {
// id used for consolidated debouncer
this._templatizerId = this._templatizerStatic.count++;
},

templatize: function(template) {
this._templatized = template;
// TODO(sjmiles): supply _alternate_ content reference missing from root
// templates (not nested). `_content` exists to provide content sharing
// for nested templates.
Expand All @@ -25,7 +42,7 @@
this.ctor = template._content._ctor;
//console.log('Templatizer.templatize: using memoized archetype');
// forward parent properties to archetype
this._prepParentProperties(this.ctor.prototype);
this._prepParentProperties(this.ctor.prototype, template);
return;
}
// `archetype` is the prototype of the anonymous
Expand All @@ -41,7 +58,7 @@
archetype._prepBindings();

// forward parent properties to archetype
this._prepParentProperties(archetype);
this._prepParentProperties(archetype, template);

// boilerplate code
archetype._notifyPath = this._notifyPathImpl;
Expand All @@ -64,18 +81,33 @@
return (this.dataHost && this.dataHost._rootDataHost) || this.dataHost;
},

_getAllStampedChildren: function(children) {
children = children || [];
if (this._getStampedChildren) {
var c$ = this._getStampedChildren();
for (var i=0, c; c = c$[i]; i++) {
children.push(c);
if (c._getAllStampedChildren) {
c._getAllStampedChildren(children);
}
_hideTemplateChildrenChanged: function(hidden) {
if (this._hideChildren) {
// Extension point for Templatizer sub-classes
// TODO(kschaaf): remove once element protos can override behaviors
this._hideChildren(hidden);
}
},

_debounceTemplate: function(fn) {
this._templatizerStatic.callbacks[this._templatizerId] = fn.bind(this);
this._templatizerStatic.debouncer =
Polymer.Debounce(this._templatizerStatic.debouncer,
this._flushTemplates.bind(this, true));
},

_flushTemplates: function(debouncerExpired) {
var db = this._templatizerStatic.debouncer;
// completely flush any re-queued callbacks resulting from stamping
while (debouncerExpired || (db && db.finish)) {
db.stop();
var cbs = this._templatizerStatic.callbacks;
this._templatizerStatic.callbacks = {};
for (var id in cbs) {
cbs[id]();
}
debouncerExpired = false;
}
return children;
},

customPrepAnnotations: function(archetype, template) {
Expand Down Expand Up @@ -107,14 +139,14 @@
// API that should be implemented by Templatizer users to get parent
// properties to their template instances. These accessors are memoized
// on the archetype and copied to instances.
_prepParentProperties: function(archetype) {
_prepParentProperties: function(archetype, template) {
var parentProps = this._parentProps = archetype._parentProps;
if (this._forwardParentProp && parentProps) {
// Prototype setup (memoized on archetype)
var proto = archetype._parentPropProto;
if (!proto) {
proto = archetype._parentPropProto = Object.create(null);
if (this._templatized != this) {
if (template != this) {
// Assumption: if `this` isn't the template being templatized,
// assume that the template is not a Poylmer.Base, so prep it
// for binding
Expand All @@ -133,12 +165,12 @@
}
}
// Instance setup
if (this._templatized != this) {
Polymer.Bind.prepareInstance(this._templatized);
this._templatized._forwardParentProp =
if (template != this) {
Polymer.Bind.prepareInstance(template);
template._forwardParentProp =
this._forwardParentProp.bind(this);
}
this._extendTemplate(this._templatized, proto);
this._extendTemplate(template, proto);
}
},

Expand Down
31 changes: 17 additions & 14 deletions src/lib/template/x-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
],

observers: [
'_render(if, restamp)'
'_queueRender(if, restamp)'
],

_render: function() {
this.debounce('render', this.render);
_queueRender: function() {
this._debounceTemplate(this._render);
},

detached: function() {
Expand All @@ -61,18 +61,22 @@
},

render: function() {
this.flushDebouncer('render');
this._flushTemplates();
},

_render: function() {
if (this.if) {
if (!this.ctor) {
this._wrapTextNodes(this._content || this.content);
this.templatize(this);
}
this._ensureInstance();
this._hideTemplateChildren = false;
} else if (this.restamp) {
this._teardownInstance();
}
if (!this.restamp && this._instance) {
this._showHideInstance(this.if);
this._hideTemplateChildren = !this.if;
}
},

Expand Down Expand Up @@ -114,16 +118,15 @@
},

// Implements extension point from Templatizer mixin
_getStampedChildren: function() {
return this._instance ? this._instance._children : [];
},

_showHideInstance: function(showing) {
this._getAllStampedChildren().forEach(function(n) {
if (n.setAttribute) {
this.serializeValueToAttribute(!showing, 'hidden', n);
_hideChildren: function(hidden) {
if (this._instance) {
var c$ = this._instance._children;
for (var i=0; i<c$.length; i++) {
var c = c$[i];
c.style.display = hidden ? 'none' : '';
c._hideTemplateChildren = hidden;
}
}, this);
}
},

// Implements extension point from Templatizer mixin
Expand Down
34 changes: 22 additions & 12 deletions src/lib/template/x-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
this._sortFn = this.sort && (typeof this.sort == 'function' ?
this.sort : dataHost[this.sort].bind(dataHost));
if (this.items) {
this.debounce('render', this.render);
this._debounceTemplate(this._render);
}
},

Expand All @@ -194,7 +194,7 @@
this._filterFn = this.filter && (typeof this.filter == 'function' ?
this.filter : dataHost[this.filter].bind(dataHost));
if (this.items) {
this.debounce('render', this.render);
this._debounceTemplate(this._render);
}
},

Expand All @@ -208,7 +208,7 @@
this._unobserveCollection();
if (change.value) {
this._observeCollection(change.value);
this.debounce('render', this.render);
this._debounceTemplate(this._render);
}
} else {
this._forwardItemPath(change.path, change.value);
Expand All @@ -222,7 +222,11 @@
var paths = this._observePaths;
for (var i=0; i<paths.length; i++) {
if (path.indexOf(paths[i]) === 0) {
this.debounce('render', this.render, this.delay);
if (this.delay) {
this.debounce('render', this._render, this.delay);
} else {
this._debounceTemplate(this._render);
}
return;
}
}
Expand All @@ -240,8 +244,11 @@
}
},

render: function(splices) {
this.flushDebouncer('render');
render: function() {
this._flushTemplates();
},

_render: function(splices) {
var c = this.collection;
if (splices) {
if (this._sortFn || splices[0].index == null) {
Expand Down Expand Up @@ -440,16 +447,19 @@
},

// Implements extension point from Templatizer mixin
_getStampedChildren: function() {
var children = [];
_hideChildren: function(hidden) {
if (this.rows) {
for (var i=0; i<this.rows.length; i++) {
var c = this.rows[i]._children;
for (var j=0; j<c.length; j++)
children.push(c[j]);
var c$ = this.rows[i]._children;
for (var j=0; j<c$.length; j++) {
var c = c$[j];
if (c.style) {
c.style.display = hidden ? 'none' : '';
}
c._hideTemplateChildren = hidden;
}
}
}
return children;
},

// Implements extension point from Templatizer
Expand Down
Loading