Skip to content

Commit

Permalink
Correct handling of offsets with culling recycler (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmoore authored Nov 16, 2016
1 parent d042f36 commit fca3152
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/shared/js/recycler.html
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@
this._jump(iface, placeholders, lower, currentCount, recycler);
}

this._pushUp(iface, placeholders, deltaCount, available, recycler);
if (!destructive) {
this._pushUp(iface, placeholders, deltaCount, available, recycler);
}
} else {
if (deltaCount < 0) {
this._cutUp(iface, placeholders, -deltaCount, available, recycler);
Expand All @@ -479,8 +481,8 @@
}
}
} else if (deltaCount < 0) {
this._cutUp(iface, placeholders, deltaUpper, available, recycler);
this._cutDown(iface, placeholders, -deltaLower, available, recycler);
this._cutUp(iface, placeholders, -deltaUpper, available, recycler);
this._cutDown(iface, placeholders, deltaLower, available, recycler);
}
} else {
if (deltaUpper < 0) {
Expand All @@ -491,7 +493,9 @@
this._jump(iface, placeholders, lower, currentCount, recycler);
}

this._pushDown(iface, placeholders, deltaCount, available, recycler);
if (!destructive) {
this._pushDown(iface, placeholders, deltaCount, available, recycler);
}
} else {
if (deltaCount < 0) {
this._cutDown(iface, placeholders, -deltaCount, available, recycler);
Expand All @@ -506,8 +510,10 @@
}
}
} else if (deltaCount > 0) {
this._pushUp(iface, placeholders, deltaUpper, available, recycler);
this._pushDown(iface, placeholders, -deltaLower, available, recycler);
if (!destructive) {
this._pushUp(iface, placeholders, deltaUpper, available, recycler);
this._pushDown(iface, placeholders, -deltaLower, available, recycler);
}
}
}
};
Expand Down
27 changes: 24 additions & 3 deletions src/strand-item-recycler/strand-item-recycler.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,28 @@ found here: https://github.com/Polymer/core-list
if (added = 0|mutation.addedCount) {
itemRecycler._measurements.addHeights(mutation.index, added);
// height initialization array required to keep _middleHeight accurate
transactor.addHeightsAtIndex(mutation.index, added, new Array(added));
if (itemRecycler._itemHeight) {
deltaHeight += itemRecycler._getItemHeight() * added;
}
transactor.addHeightsAtIndex(mutation.index, added, itemRecycler._spliceHeights(added));
}
}

itemRecycler._deltaMiddleHeight(deltaHeight);
itemRecycler._applyTransform();
},

_spliceHeights: function (amount) {
var count = 0|amount;
var index = 0;
var list = new Array(count);
var size = this._itemHeight ? this._getItemHeight() : 0;

for (index; index < count; index++) {
list[index] = size;
}

return list;
},

_dataSpliced: function(record) {
Expand Down Expand Up @@ -330,7 +347,7 @@ found here: https://github.com/Polymer/core-list
this._setMeasuring(true);
}
this._recycler.transactHeightMutations(this._spliceTxn, this, splices);
this.cull();
this.async(this.cull);
}

at = this._recycler.getLowestIndex();
Expand Down Expand Up @@ -517,7 +534,7 @@ found here: https://github.com/Polymer/core-list
this._itemHeight = roundMaybe(bound.height);

if (initialization) {
change = (this._getDataLength() - 1) * adjustment;
change = (this._getDataLength() - this._measurements.getDiscreteCount()) * adjustment;
if (this._viewportHeight <= 0) {
change -= 1; // accounting for enforced minimum from _initializeViewport()
}
Expand Down Expand Up @@ -583,6 +600,8 @@ found here: https://github.com/Polymer/core-list
this._provideMarginOfError();
this._recycler.cull();
this._denyMarginOfError();

this.async(this._modifyPadding, 1);
},

_changeOffsetsAfter: function (nthDOM, delta) {
Expand Down Expand Up @@ -822,6 +841,7 @@ found here: https://github.com/Polymer/core-list
bound = this._includeBoundAtIndex(-1 - index, young, spliced, useLightDom);
count++;
} else if (young < 0) {
this.debounce("offset-removal", this._modifyPadding);
bound = this._excludeBoundAtIndex(-1 - index, old, spliced);
bound = null;
while (count-- > 0 && !binds[count]) {
Expand All @@ -838,6 +858,7 @@ found here: https://github.com/Polymer/core-list
bound = this._includeBoundAtIndex(index, young, spliced, useLightDom);
count++;
} else if (young < 0) {
this.debounce("offset-removal", this._modifyPadding);
bound = this._excludeBoundAtIndex(index, old, spliced);
bound = null;
while (count-- > 0 && !binds[count]) {
Expand Down

0 comments on commit fca3152

Please sign in to comment.