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

Fixes #3065: Add dom-repeat.renderedItemCount property #3066

Merged
merged 2 commits into from
Dec 8, 2015
Merged
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
14 changes: 14 additions & 0 deletions src/lib/template/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@
*/
delay: Number,

/**
* Count of currently rendered items after `filter` (if any) has been applied.
* If "chunking mode" is enabled, `renderedItemCount` is updated each time a
* set of template instances is rendered.
*
*/
renderedItemCount: {
type: Number,
notify: true,
readOnly: true
},

/**
* Defines an initial count of template instances to render after setting
* the `items` array, before the next paint, and puts the `dom-repeat`
Expand Down Expand Up @@ -438,6 +450,8 @@
// `item` may not be sufficient if the pooled instance happens to be
// the same item.
this._pool.length = 0;
// Set rendered item count
this._setRenderedItemCount(this._instances.length);
// Notify users
this.fire('dom-change');
// Check to see if we need to render more items
Expand Down
19 changes: 19 additions & 0 deletions test/unit/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ <h4>x-repeat-chunked</h4>
test('basic rendering, downward item binding', function() {
var stamped = Polymer.dom(configured.root).querySelectorAll('*:not(template)');
assert.equal(stamped.length, 3 + 3*3 + 3*3*3, 'total stamped count incorrect');
assert.equal(configured.$.repeater.renderedItemCount, 3, 'rendered item count incorrect');
assert.equal(stamped[0].itemaProp, 'prop-1');
assert.equal(stamped[0].computeda, 'prop-1+itemForComputedA');
assert.equal(stamped[0].indexa, 0);
Expand Down Expand Up @@ -282,6 +283,7 @@ <h4>x-repeat-chunked</h4>
CustomElements.takeRecords();
var stamped = Polymer.dom(configured.root).querySelectorAll('*:not(template)');
assert.equal(stamped.length, 2 + 2*3 + 2*3*3, 'total stamped count incorrect');
assert.equal(configured.$.repeater.renderedItemCount, 2, 'rendered item count incorrect');
assert.equal(stamped[0].itemaProp, 'prop-1');
assert.equal(stamped[0].indexa, 0);
assert.equal(stamped[13].itemaProp, 'prop-3');
Expand Down Expand Up @@ -3309,6 +3311,23 @@ <h4>x-repeat-chunked</h4>
assert.equal(repeater3.keyForElement(stamped1[4]), coll3.getKey(items3[2]));
});

test('renderedItemCount', function() {
var repeater1 = primitive.$.repeater1;
primitive.items = [ 'a', 'b', 'c', 'd', 'e' ];
repeater1.render();
assert.equal(repeater1.renderedItemCount, 5, 'renderedItemCount is incorrect');
repeater1.renderedItemCount = 0;
assert.equal(repeater1.renderedItemCount, 5, 'renderedItemCount is writable');
repeater1.filter = function(item) {
return (item != 'a' && item != 'e');
}
repeater1.render();
assert.equal(repeater1.renderedItemCount, 3, 'renderedItemCount incorrect after filter');
// reset repeater
repeater1.filter = undefined;
repeater1.render();
});

test('__hideTemplateChildren__', function() {
// Initially all showing
var stamped1 = Polymer.dom(primitive.$.container1).querySelectorAll('*:not(template)');
Expand Down