Skip to content

Commit

Permalink
Change observer to fix PolymerElements#112.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmwhite committed Mar 11, 2016
1 parent 06bd256 commit 79cb098
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion iron-multi-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},

observers: [
'_updateSelected(selectedValues)'
'_updateSelected(selectedValues.splices)'
],

/**
Expand Down
37 changes: 36 additions & 1 deletion test/multi.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

// programatically select values 0 and 1 (both fire select)
s.selectedValues = [0, 1];

// programatically select values 1 and 2 (2 fires select, 0 fires deselect)
s.selectedValues = [1, 2];

Expand All @@ -135,6 +135,41 @@
assert.equal(deselectEventCounters[2], 1);
});

test('fire iron-select/deselect events when selectedValues is modified', function() {
// setup listener for iron-select/deselect events
var items = [s.children[0], s.children[1], s.children[2]],
selectEventCounters = [0, 0, 0],
deselectEventCounters = [0, 0, 0];

s.addEventListener('iron-select', function(e) {
selectEventCounters[items.indexOf(e.detail.item)]++;
});
s.addEventListener('iron-deselect', function(e) {
deselectEventCounters[items.indexOf(e.detail.item)]++;
});

s.selectedValues = []

// programatically select value 0
s.push('selectedValues', 0, 1);

// programatically deselect value 0
s.shift('selectedValues');

// programatically select value 2
s.push('selectedValues', 2);

// programatically deselect value 1
s.shift('selectedValues');

assert.equal(selectEventCounters[0], 1);
assert.equal(deselectEventCounters[0], 1);
assert.equal(selectEventCounters[1], 1);
assert.equal(deselectEventCounters[1], 1);
assert.equal(selectEventCounters[2], 1);
assert.equal(deselectEventCounters[2], 0);
});

test('fire iron-select/deselect events when toggling items', function() {
// setup listener for iron-select/deselect events
var items = [s.children[0], s.children[1], s.children[2]],
Expand Down

0 comments on commit 79cb098

Please sign in to comment.