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

Notify array.length changes. Fixes #1573. #1600

Merged
merged 1 commit into from
May 23, 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
3 changes: 3 additions & 0 deletions src/standard/notify-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@
indexSplices: splices
};
this.set(path + '.splices', change);
if (added != removed.length) {
this.notifyPath(path + '.length', array.length);
}
// Null here to allow potentially large splice records to be GC'ed
change.keySplices = null;
change.indexSplices = null;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/notify-path-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<x-basic id="basic" notifying-value="{{nested.obj.value}}" attrvalue$="{{nested.obj.value}}"></x-basic>
<x-compose id="compose" obj="{{nested.obj}}"></x-compose>
<x-forward id="forward" obj="{{nested.obj}}"></x-forward>
<div id="boundChild" computed-from-paths="{{computeFromPaths(a, nested.b, nested.obj.c)}}"></div>
<div id="boundChild" computed-from-paths="{{computeFromPaths(a, nested.b, nested.obj.c)}}" array-length="{{data.length}}"></div>
</template>
<script>
Polymer({
Expand Down
19 changes: 19 additions & 0 deletions test/unit/notify-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,25 @@
assert.equal(el.observerCounts.arrayOrPropChanged, 1);
});

test('array.length notified', function() {
el.data = [];
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.push('data', 1, 2, 3);
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.pop('data');
el.pop('data');
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.unshift('data', 1, 2);
el.unshift('data', 1, 2, 3);
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.splice('data', 2, 2, 1, 2, 3);
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.shift('data');
el.shift('data');
el.shift('data');
assert.equal(el.$.boundChild.arrayLength, el.data.length);
});

});

suite('path API', function() {
Expand Down