Skip to content

Commit

Permalink
Avoid creating unnecessary placeholders for full refresh.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Nov 5, 2015
1 parent c5e1135 commit 996289a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib/template/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,13 @@
}
this._keySplices = [];
this._indexSplices = [];
// Update final _keyToInstIdx, instance indices, and replace placeholders
// Update final _keyToInstIdx and instance indices, and
// upgrade/downgrade placeholders
var keyToIdx = this._keyToInstIdx = {};
for (var i=this._instances.length-1; i>=0; i--) {
var inst = this._instances[i];
if (inst.isPlaceholder && i<this._limit) {
inst = this._upgradePlaceholder(i, inst.__key__);
inst = this._insertInstance(i, inst.__key__);
} else if (!inst.isPlaceholder && i>=this._limit) {
inst = this._downgradeInstance(i, inst.__key__);
}
Expand Down Expand Up @@ -484,6 +485,8 @@
if (!inst.isPlaceholder && i < this._limit) {
inst.__setProperty(this.as, c.getItem(key), true);
}
} else if (i < this._limit) {
this._insertInstance(i, key);
} else {
this._insertPlaceholder(i, key);
}
Expand Down Expand Up @@ -646,7 +649,7 @@
});
},

_generateInstance: function(idx, key) {
_stampInstance: function(idx, key) {
var model = {
__key__: key
};
Expand All @@ -655,15 +658,15 @@
return this.stamp(model);
},

_upgradePlaceholder: function(idx, key) {
_insertInstance: function(idx, key) {
var inst = this._pool.pop();
if (inst) {
// TODO(kschaaf): If the pool is shared across turns, parentProps
// need to be re-set to reused instances in addition to item/key
inst.__setProperty(this.as, this.collection.getItem(key), true);
inst.__setProperty('__key__', key, true);
} else {
inst = this._generateInstance(idx, key);
inst = this._stampInstance(idx, key);
}
var beforeRow = this._instances[idx + 1 ];
var beforeNode = beforeRow && !beforeRow.isPlaceholder ? beforeRow._children[0] : this;
Expand Down

0 comments on commit 996289a

Please sign in to comment.