Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More performant attempt at solving #300 #487

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions iron-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,9 @@
return this._viewportHeight === 0 ? Infinity : this._viewportHeight * this._maxPages;
},

/**
* True if the current list is visible.
*/
/**
* True if the current list is visible.
*/
get _isVisible() {
return Boolean(this.offsetWidth || this.offsetHeight);
},
Expand Down Expand Up @@ -1214,6 +1214,15 @@
return this._virtualStart + (this._physicalCount - this._physicalStart) + pidx;
},

/**
* Can be used to expand the item update logic to include any fields that
* you need to update within the template for your virtual item.
*
* @param {Object} item - the item that you passed in
* @param {Object} instance - the current instance in the list
*/
_propagateUpdates(item, instance) {},

/**
* Assigns the data models to a given set of items.
* @param {!Array<number>=} itemSet
Expand All @@ -1224,6 +1233,7 @@
var item = this.items && this.items[vidx];
if (item != null) {
var inst = this.modelForElement(el);
this._propagateUpdates(item, inst);
inst.__key__ = this._collection ? this._collection.getKey(item) : null;
this._forwardProperty(inst, this.as, item);
this._forwardProperty(inst, this.selectedAs, this.$.selector.isSelected(item));
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/x-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<div class="item" selected$="[[selected]]">
<div style$="[[_computedItemHeight(item)]]" tabindex$="[[_computedTabIndex(tabIndex, useTabIndex)]]" hidden$="[[primitive]]">[[item.index]]</div>
<div style$="[[_computedItemHeight(item)]]" tabindex$="[[_computedTabIndex(tabIndex, useTabIndex)]]" hidden$="[[!primitive]]">[[item]]</div>
<div id="prop">[[item.prop]]</div>
</div>
</template>
</iron-list>
Expand Down
23 changes: 22 additions & 1 deletion test/mutations.html
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,27 @@
PolymerFlush();
assert.equal(getFirstItemFromList(list).textContent, 'correct');
});

test('Issue #300: update properties when item properties update', () => {
list.items = buildDataSet(10);
PolymerFlush();
list.scrollToIndex(1);
assert.equal(list.children[2].querySelector('#prop').innerHTML, '');
assert.equal(list.children[3].querySelector('#prop').innerHTML, '');
var item = list.items[1];
item.prop = 'prop';
list.splice('items', 1, 1, item);
PolymerFlush();
assert.equal(list.children[2].querySelector('#prop').innerHTML, '');
item = list.items[2];
item.prop = 'prop2';
list._propagateUpdates = function (item, instance) {
instance.notifyPath('item.prop', item.prop);
};
list.splice('items', 2, 1, item);
PolymerFlush();
assert.equal(list.children[3].querySelector('#prop').innerHTML, 'prop2');
});
});

suite('mutableData', function() {
Expand All @@ -338,7 +359,7 @@
test('should not use dirty checking if mutableData is true', function() {
/**
* This feature and Polymer.OptionalMutableDataBehavior is only available
* with Polymer 2.0.
* with Polymer 2.0.
*/
if (!Polymer.OptionalMutableDataBehavior.properties) {
return;
Expand Down