Skip to content

Commit 4a45d4f

Browse files
committed
Always use placeholders; fix insertion reference bug.
1 parent 4eda393 commit 4a45d4f

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

‎src/lib/template/dom-repeat.html‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@
341341
},
342342

343343
// Render method 1: full refesh
344+
// ----
345+
// Full list of keys is pulled from the collection, then sorted, filtered,
346+
// and interated to create (or reuse) existing instances
344347
_applyFullRefresh: function() {
345348
var c = this.collection;
346349
// Start with unordered keys for view sort,
@@ -391,6 +394,10 @@
391394
return this.collection.getKey(a) - this.collection.getKey(b);
392395
},
393396

397+
// Render method 2: incremental update using splices with user sort applied
398+
// ----
399+
// Removed/added keys are deduped, all removed rows are detached and pooled
400+
// first, and added rows are insertion-sorted into place using user sort
394401
_applySplicesUserSort: function(splices) {
395402
var c = this.collection;
396403
var keys = this._keys;
@@ -484,6 +491,12 @@
484491
return idx;
485492
},
486493

494+
// Render method 3: incremental update using splices with array sort
495+
// ----
496+
// Splices are processed in order; removed rows are pooled, and added
497+
// rows are inserted based on splice index; placeholders are used when
498+
// inserting rows when pool is empty, and placeholders are updated to
499+
// actual rows at the end to take full advantage of removed rows
487500
_applySplicesArrayOrder: function(splices) {
488501
var keys = this._keys;
489502
var pool = [];
@@ -500,19 +513,14 @@
500513
}
501514
}
502515
this._instances.splice(s.index, s.removed.length);
503-
// Insert new instances (from pool or placeholder)
516+
// Insert placeholders for new rows
504517
for (var i=0; i<s.added.length; i++) {
505-
var inst;
506-
if (pool.length) {
507-
inst = this._insertRow(s.index + i, pool, s.added[i]);
508-
} else {
509-
var beforeRow = this._instances[s.index + i];
510-
inst = {
511-
isPlaceholder: true,
512-
key: s.added[i],
513-
_children: [beforeRow ? beforeRow._children[0] : null]
514-
};
515-
}
518+
var beforeRow = this._instances[s.index + i];
519+
var inst = {
520+
isPlaceholder: true,
521+
key: s.added[i],
522+
_children: [beforeRow ? beforeRow._children[0] : this]
523+
};
516524
this._instances.splice(s.index + i, 0, inst);
517525
}
518526
}, this);

0 commit comments

Comments
 (0)