Skip to content

Commit

Permalink
Merge pull request #1600 from Polymer/1573-kschaaf
Browse files Browse the repository at this point in the history
Notify array.length changes.  Fixes #1573.
  • Loading branch information
Steve Orvell committed May 23, 2015
2 parents 9ea9d8e + 0a06a72 commit 3b1d038
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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

0 comments on commit 3b1d038

Please sign in to comment.