Skip to content

Commit

Permalink
Remove duplicate code related to dom traversal in Polymer.dom.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Jan 5, 2016
1 parent 7c20170 commit 555252b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
22 changes: 0 additions & 22 deletions src/lib/dom-api-shadow.html
Expand Up @@ -26,28 +26,6 @@
return TreeApi.arrayCopy(this.node.querySelectorAll(selector));
},

_query: function(matcher, node) {
node = node || this.node;
var list = [];
this._queryElements(node.childNodes, matcher, list);
return list;
},

_queryElements: function(elements, matcher, list) {
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
if (c.nodeType === Node.ELEMENT_NODE) {
this._queryElement(c, matcher, list);
}
}
},

_queryElement: function(node, matcher, list) {
if (matcher(node)) {
list.push(node);
}
this._queryElements(node.childNodes, matcher, list);
},

getOwnerRoot: function() {
var n = this.node;
while (n) {
Expand Down
22 changes: 0 additions & 22 deletions src/lib/dom-api-shady.html
Expand Up @@ -354,28 +354,6 @@
}, this.node);
},

_query: function(matcher, node) {
node = node || this.node;
var list = [];
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
return list;
},

_queryElements: function(elements, matcher, list) {
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
if (c.nodeType === Node.ELEMENT_NODE) {
this._queryElement(c, matcher, list);
}
}
},

_queryElement: function(node, matcher, list) {
if (matcher(node)) {
list.push(node);
}
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
},

getDestinationInsertionPoints: function() {
return this.node._destinationInsertionPoints || [];
},
Expand Down
26 changes: 26 additions & 0 deletions src/lib/dom-api.html
Expand Up @@ -21,6 +21,7 @@
'use strict';

var Settings = Polymer.Settings;
var TreeApi = Polymer.TreeApi;

var DomApi = function(node) {
this.node = needsToWrap ? DomApi.wrap(node) : node;
Expand Down Expand Up @@ -134,6 +135,31 @@
if (this.observer) {
this.observer.notify();
}
},

// NOTE: `_query` is used primarily for ShadyDOM's querySelector impl,
// but it's also generally useful to recurse through the element tree
// and is used by Polymer's styling system.
_query: function(matcher, node) {
node = node || this.node;
var list = [];
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
return list;
},

_queryElements: function(elements, matcher, list) {
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
if (c.nodeType === Node.ELEMENT_NODE) {
this._queryElement(c, matcher, list);
}
}
},

_queryElement: function(node, matcher, list) {
if (matcher(node)) {
list.push(node);
}
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
}

};
Expand Down

0 comments on commit 555252b

Please sign in to comment.