Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Use observeNodes in favor of MutationObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Joel committed Oct 14, 2015
1 parent dca7800 commit e30b050
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
24 changes: 3 additions & 21 deletions iron-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

/**
* Returns the currently selected item.
*
*
* @type {?Object}
*/
selectedItem: {
Expand Down Expand Up @@ -133,7 +133,6 @@

attached: function() {
this._observer = this._observeItems(this);
this._contentObserver = this._observeContent(this);
if (!this.selectedItem && this.selected) {
this._updateSelected(this.attrForSelected,this.selected)
}
Expand All @@ -142,10 +141,7 @@

detached: function() {
if (this._observer) {
this._observer.disconnect();
}
if (this._contentObserver) {
this._contentObserver.disconnect();
Polymer.dom(this).unobserveNodes(this._observer);
}
this._removeListener(this.activateEvent);
},
Expand Down Expand Up @@ -274,18 +270,9 @@
this._setSelectedItem(this._selection.get());
},

// observe content changes under the given node.
_observeContent: function(node) {
var content = node.querySelector('content');
if (content && content.parentElement === node) {
return this._observeItems(node.domHost);
}
},

// observe items change under the given node.
_observeItems: function(node) {
// TODO(cdata): Update this when we get distributed children changed.
var observer = new MutationObserver(function(mutations) {
return Polymer.dom(node).observeNodes(function(mutations) {
// Let other interested parties know about the change so that
// we don't have to recreate mutation observers everywher.
this.fire('iron-items-changed', mutations, {
Expand All @@ -297,11 +284,6 @@
this._updateSelected();
}
}.bind(this));
observer.observe(node, {
childList: true,
subtree: true
});
return observer;
},

_activateHandler: function(e) {
Expand Down
4 changes: 2 additions & 2 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@
changeCount++;
});

s2.appendChild(newItem);
Polymer.dom(s2).appendChild(newItem);

Polymer.Base.async(function() {
s2.removeChild(newItem);
Polymer.dom(s2).removeChild(newItem);

Polymer.Base.async(function() {
expect(changeCount).to.be.equal(2);
Expand Down

0 comments on commit e30b050

Please sign in to comment.