From d4e714008a29880c814f94494bcd4bcac57a20c3 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 7 Aug 2015 16:51:52 -0700 Subject: [PATCH] Default selected to empty array. Add isSelected API. --- src/lib/template/array-selector.html | 45 ++++++++++++++-------------- test/unit/array-selector.html | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/lib/template/array-selector.html b/src/lib/template/array-selector.html index 7c5a3f1b98..246a12f197 100644 --- a/src/lib/template/array-selector.html +++ b/src/lib/template/array-selector.html @@ -73,7 +73,8 @@ * An array containing items from which selection will be made. */ items: { - type: Array + type: Array, + observer: '_resetSelection' }, /** @@ -102,15 +103,11 @@ */ multi: { type: Boolean, - value: false + observer: '_resetSelection' } }, - observers: [ - '_resetSelection(items, multi)' - ], - - _resetSelection: function(items, multi) { + _resetSelection: function() { // Unbind previous selection if (Array.isArray(this.selected)) { for (var i=0; i= 0) { - var sidx = this.selected.indexOf(item); - if (sidx >= 0) { - var skey = scol.getKey(item); - this.splice('selected', sidx, 1); - // scol.remove(item); + if (this.isSelected(item)) { + var skey = this._selectedColl.getKey(item); + this.arrayDelete('selected', item); this.unlinkPaths('selected.' + skey); return true; } @@ -157,16 +161,13 @@ var icol = Polymer.Collection.get(this.items); var key = icol.getKey(item); if (this.multi) { - // var sidx = this.selected.indexOf(item); - // if (sidx < 0) { - var scol = Polymer.Collection.get(this.selected); - if (scol.getKey(item) !== undefined) { + if (this.isSelected(item)) { if (this.toggle) { this.deselect(item); } } else { this.push('selected', item); - skey = scol.getKey(item); + skey = this._selectedColl.getKey(item); this.linkPaths('selected.' + skey, 'items.' + key); } } else { diff --git a/test/unit/array-selector.html b/test/unit/array-selector.html index b706bc3a16..31ee18f2d3 100644 --- a/test/unit/array-selector.html +++ b/test/unit/array-selector.html @@ -82,7 +82,7 @@ test('bound defaults', function() { assert.equal(bind.$.observer.singleSelected, null); - assert.equal(bind.$.observer.multiSelected, null); + assert.sameMembers(bind.$.observer.multiSelected, []); bind.items = [ {name: 'one'}, {name: 'two'},