|
330 | 330 | this._splices = [];
|
331 | 331 | // Update final _keyToInstIdx and instance indices
|
332 | 332 | var keyToIdx = this._keyToInstIdx = {};
|
333 |
| - var keys = this._keys; |
334 |
| - for (var i=0; i<keys.length; i++) { |
335 |
| - var key = keys[i]; |
336 |
| - keyToIdx[key] = i; |
| 333 | + for (var i=0; i<this._instances.length; i++) { |
337 | 334 | var inst = this._instances[i];
|
| 335 | + keyToIdx[inst.__key__] = i; |
338 | 336 | inst.__setProperty(this.indexAs, i, true);
|
339 | 337 | }
|
340 | 338 | this.fire('dom-change');
|
|
348 | 346 | var c = this.collection;
|
349 | 347 | // Start with unordered keys for user sort,
|
350 | 348 | // or get them in array order for array order
|
| 349 | + var keys; |
351 | 350 | if (this._sortFn) {
|
352 |
| - this._keys = c ? c.getKeys() : []; |
| 351 | + keys = c ? c.getKeys() : []; |
353 | 352 | } else {
|
354 |
| - this._keys = []; |
| 353 | + keys = []; |
355 | 354 | var items = this.items;
|
356 | 355 | if (items) {
|
357 | 356 | for (var i=0; i<items.length; i++) {
|
358 |
| - this._keys.push(c.getKey(items[i])); |
| 357 | + keys.push(c.getKey(items[i])); |
359 | 358 | }
|
360 | 359 | }
|
361 | 360 | }
|
362 | 361 | // Apply user filter to keys
|
363 | 362 | if (this._filterFn) {
|
364 |
| - this._keys = this._keys.filter(function(a) { |
| 363 | + keys = keys.filter(function(a) { |
365 | 364 | return this._filterFn(c.getItem(a));
|
366 | 365 | }, this);
|
367 | 366 | }
|
368 | 367 | // Apply user sort to keys
|
369 | 368 | if (this._sortFn) {
|
370 |
| - this._keys.sort(function(a, b) { |
| 369 | + keys.sort(function(a, b) { |
371 | 370 | return this._sortFn(c.getItem(a), c.getItem(b));
|
372 | 371 | }.bind(this));
|
373 | 372 | }
|
374 | 373 | // Generate instances and assign items and keys
|
375 |
| - var keys = this._keys; |
376 | 374 | for (var i=0; i<keys.length; i++) {
|
377 | 375 | var key = keys[i];
|
378 | 376 | var inst = this._instances[i];
|
|
400 | 398 | // first, and added rows are insertion-sorted into place using user sort
|
401 | 399 | _applySplicesUserSort: function(splices) {
|
402 | 400 | var c = this.collection;
|
403 |
| - var keys = this._keys; |
404 | 401 | var instances = this._instances;
|
405 | 402 | var keyMap = {};
|
406 | 403 | var pool = [];
|
|
438 | 435 | if (idx !== undefined) {
|
439 | 436 | pool.push(this._detachRow(idx));
|
440 | 437 | instances.splice(idx, 1);
|
441 |
| - keys.splice(idx, 1); |
442 | 438 | }
|
443 | 439 | }
|
444 | 440 | }
|
|
471 | 467 | // Binary search for insertion point
|
472 | 468 | while (start <= end) {
|
473 | 469 | var mid = (start + end) >> 1;
|
474 |
| - var midKey = this._keys[mid]; |
| 470 | + var midKey = this._instances[mid].__key__; |
475 | 471 | var cmp = sortFn(c.getItem(midKey), item);
|
476 | 472 | if (cmp < 0) {
|
477 | 473 | start = mid + 1;
|
|
485 | 481 | if (idx < 0) {
|
486 | 482 | idx = end + 1;
|
487 | 483 | }
|
488 |
| - // Insert key & inst at insertion point |
489 |
| - this._keys.splice(idx, 0, key); |
| 484 | + // Insert instance at insertion point |
490 | 485 | this._instances.splice(idx, 0, this._insertRow(idx, key, pool));
|
491 | 486 | return idx;
|
492 | 487 | },
|
493 | 488 |
|
494 |
| - // Render method 3: incremental update using splices with array sort |
| 489 | + // Render method 3: incremental update using splices with array order |
495 | 490 | // ----
|
496 | 491 | // 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 |
| 492 | + // rows are as placeholders, and placeholders are updated to |
499 | 493 | // actual rows at the end to take full advantage of removed rows
|
500 | 494 | _applySplicesArrayOrder: function(splices) {
|
501 |
| - var keys = this._keys; |
502 | 495 | var pool = [];
|
503 | 496 | var c = this.collection;
|
504 | 497 | splices.forEach(function(s) {
|
505 |
| - // Apply splices to keys |
506 |
| - var args = [s.index, s.removed.length].concat(s.added); |
507 |
| - keys.splice.apply(keys, args); |
508 | 498 | // Detach & pool removed instances
|
509 | 499 | for (var i=0; i<s.removed.length; i++) {
|
510 | 500 | var inst = this._detachRow(s.index + i);
|
|
0 commit comments