Skip to content

Commit

Permalink
Improve consistency constraints when splicing recycler
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Moore committed Apr 11, 2016
1 parent dcd5044 commit 5bf2ea5
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 66 deletions.
8 changes: 4 additions & 4 deletions src/mm-grid/mm-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
}

if (model && index > -1) {
this.set("data."+index+".selected", model.selected);
this.set("data.#"+index+".selected", model.selected);
}

this._selectAllState = state;
Expand All @@ -165,7 +165,7 @@
this._selectAllState = value ? "checked" : "unchecked";
if (this.data) {
this.data.forEach(function(item, i) {
var path = 'data.'+i+'.selected';
var path = 'data.#'+i+'.selected';
this.set(path, value);
}, this);
}
Expand Down Expand Up @@ -212,7 +212,7 @@
if(column.width.indexOf("%") !== -1){
column.set('width', column.offsetWidth + 'px');
}
this.notifyPath("scope._columns."+index+".width", column.width);
this.notifyPath("scope._columns.#"+index+".width", column.width);
}, this);
},

Expand Down Expand Up @@ -253,7 +253,7 @@
this.$.viewport.inferOffviewHeightsAfterNextMutation();
if (this.data) {
this.data.forEach(function(item, index) {
this.set("data." + index + ".expanded", this.expanded);
this.set("data.#" + index + ".expanded", this.expanded);
}, this);
}
},
Expand Down
83 changes: 79 additions & 4 deletions src/mm-item-recycler/mm-item-recycler.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ found here: https://github.com/Polymer/core-list
this.pane = null;
this.header = null;
this.footer = null;
this.boundMap = {};
this.boundMap = []; // {};
}


Expand Down Expand Up @@ -724,7 +724,8 @@ found here: https://github.com/Polymer/core-list
},

_handleRecycling: function (id, young, old, recycler) {
var index = 0|id;
var spliced = 0|(id < 0);
var index = 0|(spliced ? 0|-id - 1 : id);
var bound = null;
var binds = this._bindingList;
var count = 0|(binds && binds.length);
Expand All @@ -733,7 +734,18 @@ found here: https://github.com/Polymer/core-list
var offset = this._calculateStaticPositionOffset(index, binds);
var useLightDom = 0|true;

if (old < 0) {
if (spliced) {
if (old < 0) {
bound = this._includeBoundAtIndex(index, binds, young, useLightDom);
count++;
} else if (young < 0) {
bound = this._excludeBoundAtIndex(index, binds);
count--;
bound = null;
} else {
return;
}
} else if (old < 0) {
while (count < index) {
count = binds.push(null);
}
Expand Down Expand Up @@ -772,7 +784,8 @@ found here: https://github.com/Polymer/core-list
} else {
height = recycler.getHeightAtIndex(young);
bound.pendingResponse = 0|true;
this.debounce(young, this._getBoundResponse(bound, id, index)); // defer validation of the height
// defer validation of the height
this.debounce(young, this._getBoundResponse(bound, spliced ? -1 - id : id, index));
}

if (this._measurements.isElevationKnown(young)) {
Expand All @@ -797,6 +810,68 @@ found here: https://github.com/Polymer/core-list
this.debounce("settle-down", this._settleDown, 1);
},

_includeBoundAtIndex: function (at, binds, young, useLightDom) {
var index = 0|at;
var map = this._responders.boundMap;
var count = binds.length;
var bound = new BoundReference(this, index);
var included = bound;
var replaced = index < count ? binds[index] : null;

for (count; count-- > index; ) {
bound = binds[count + 1] = binds[count];
bound.id++;
bound.young++;
map[count + 1] = map[count];
}

bound = included;
index = 0|at;

binds[index] = bound;
map[index] = null;

bound.value = new BoundValue(null, this.scope);
bound.element = document.createElement("DIV");
this.toggleClass("recycler-panel", true, bound.element);
bound.instance = this.instantiateTemplate(this._templateFound, 0|!useLightDom);

bound.instance.set("scope", this.scope);
bound.instance.set("model", this.data[young]);

Polymer.dom(bound.element).appendChild(bound.instance);
Polymer.dom(this.$.middle).insertBefore(bound.element, replaced.element);
this._addBoundResponse(bound, bound.id, index);

return bound;
},

_excludeBoundAtIndex: function (at, binds) {
var index = 0|at;
var map = this._responders.boundMap;
var count = binds.length;
var bound = binds[index];
var excluded = bound;

for (index++; index < count; index++) {
bound = binds[index - 1] = binds[index];
bound.id--;
bound.young--;
map[index - 1] = map[index];
}

binds[count - 1] = null;
map[count - 1] = null;

bound = excluded;
index = 0|at;

this._removeBoundResponse(bound, bound.id, index);
Polymer.dom(Polymer.dom(bound.element).parentNode).removeChild(bound.element);

return bound;
},

_calculateStaticPositionOffset: function (place, binds) {
var limit = 0|place;
var index = 0;
Expand Down
Loading

0 comments on commit 5bf2ea5

Please sign in to comment.