Skip to content

Commit

Permalink
Improve composed parent tracking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Aug 27, 2015
1 parent 8751b68 commit 4d15789
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@

_tryRemoveUndistributedNode: function(node) {
if (this.node.shadyRoot) {
if (node._composedParent) {
nativeRemoveChild.call(node._composedParent, node);
var parent = getComposedParent(node);
if (parent) {
nativeRemoveChild.call(parent, node);
}
return true;
}
Expand Down Expand Up @@ -289,7 +290,7 @@
this._updateInsertionPoints(root.host);
this._lazyDistribute(root.host);
} else if (ensureComposedRemoval) {
removeFromComposedParent(node._composedParent, node);
removeFromComposedParent(getComposedParent(node), node);
}
},

Expand Down Expand Up @@ -572,8 +573,7 @@
parentNode: {
get: function() {
return this.node._lightParent ||
(this.node.__patched ? this.node._composedParent :
this.node.parentNode);
getComposedParent(this.node);
},
configurable: true
},
Expand Down Expand Up @@ -909,7 +909,10 @@
} else {
addNodeToComposedChildren(node, parent, children, i);
}
}

function getComposedParent(node) {
return node.__patched ? node._composedParent : node.parentNode;
}

function addNodeToComposedChildren(node, parent, children, i) {
Expand Down Expand Up @@ -956,6 +959,7 @@

return {
getLightChildren: getLightChildren,
getComposedParent: getComposedParent,
getComposedChildren: getComposedChildren,
removeFromComposedParent: removeFromComposedParent,
saveLightChildrenIfNeeded: saveLightChildrenIfNeeded,
Expand Down
9 changes: 7 additions & 2 deletions src/mini/shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@
composed.splice(j, 0, n);
}
}
// ensure composed parent is set
ensureComposedParent(container, children);
},

_matchesContentSelect: function(node, contentElement) {
Expand Down Expand Up @@ -364,6 +366,7 @@
var matchesSelector = Polymer.DomApi.matchesSelector;
var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint;
var getComposedChildren = Polymer.DomApi.getComposedChildren;
var getComposedParent = Polymer.DomApi.getComposedParent;
var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent;

function distributeNodeInto(child, insertionPoint) {
Expand Down Expand Up @@ -434,8 +437,10 @@
}
}

function getComposedParent(node) {
return node.__patched ? node._composedParent : node.parentNode;
function ensureComposedParent(parent, children) {
for (var i=0, n; i < children.length; i++) {
children[i]._composedParent = parent;
}
}

// returns the host that's the top of this host's distribution tree
Expand Down

0 comments on commit 4d15789

Please sign in to comment.