Skip to content

Commit

Permalink
Avoid to create a new array each selection
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge del Casar <[email protected]>
  • Loading branch information
jorgecasar committed Apr 28, 2017
1 parent 6486761 commit f90849f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions iron-multi-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,19 @@
}
},

_selectionChange: function() {
var s = this._selection.get();
_selectionChange: function(isSelected, item) {
if (this.multi) {
this._setSelectedItems(s);
if (!this.selectedItems) {
this._setSelectedItems([]);
}
if (isSelected) {
this.splice('selectedItems', this.selectedItems.length, 0, item);
} else {
this.splice('selectedItems', this.selectedItems.indexOf(item), 1);
}
} else {
this._setSelectedItems([s]);
this._setSelectedItem(s);
this._setSelectedItems(isSelected?[item]:[]);
this._setSelectedItem(isSelected?item:undefined);
}
},

Expand Down
6 changes: 3 additions & 3 deletions iron-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@
if (this.selectedAttribute) {
this.toggleAttribute(this.selectedAttribute, isSelected, item);
}
this._selectionChange();
this._selectionChange(isSelected, item);
this.fire('iron-' + (isSelected ? 'select' : 'deselect'), {item: item});
},

_selectionChange: function() {
this._setSelectedItem(this._selection.get());
_selectionChange: function(isSelected, item) {
this._setSelectedItem(isSelected?item:undefined);
},

// observe items change under the given node.
Expand Down
2 changes: 1 addition & 1 deletion test/attr-for-selected.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
assert.equal(selector.selectedItem, undefined);
selector.multi = true;
selector.selectedValues = ['non-existing-value'];
assert.deepEqual(selector.selectedItems, [undefined]);
assert.deepEqual(selector.selectedItems, []);
selector.fallbackSelection = 'default';
assert.deepEqual(selector.selectedItems, [items[2]]);
});
Expand Down

0 comments on commit f90849f

Please sign in to comment.