Skip to content

Commit

Permalink
Minor factoring of dom patching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Dec 15, 2015
1 parent 9a3bead commit 8c95014
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
52 changes: 16 additions & 36 deletions src/lib/experimental/patch-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
return;
}

count = 0;

var baseFinishDistribute = Polymer.Base._finishDistribute;
var TreeApi = Polymer.TreeApi;
var DomApi = Polymer.DomApi;
Expand Down Expand Up @@ -118,8 +116,6 @@

var log = false;

var count = 0;

var patchImpl = {

hasPrototypeDescriptors: Boolean(Object.getOwnPropertyDescriptor(
Expand Down Expand Up @@ -245,25 +241,8 @@

// NOTE: patch logical implementations here so we can use
// composed getters
TreeApi.Logical.saveChildNodes = function(node) {
if (!this.hasChildNodes(node)) {
if (!node.__dom) {
node.__dom = {};
}
node.__dom.firstChild = node.firstChild;
node.__dom.lastChild = node.lastChild;
node.__dom.childNodes = [];
for (var n=TreeApi.Composed.getFirstChild(node); n;
n=TreeApi.Composed.getNextSibling(n)) {
n.__dom = n.__dom || {};
n.__dom.parentNode = node;
node.__dom.childNodes.push(n);
n.__dom.nextSibling = TreeApi.Composed.getNextSibling(n);
n.__dom.previousSibling = TreeApi.Composed.getPreviousSibling(n);
}
}
}

// TODO(sorvell): may need to patch saveChildNodes iff the tree has
// already been distributed.
TreeApi.Logical.recordInsertBefore = function(node, container, ref_node) {
container.__dom.childNodes = null;
// handle document fragments
Expand All @@ -280,18 +259,6 @@
}
}

TreeApi.Logical.getChildNodes = function(node) {
if (this.hasChildNodes(node)) {
return this._getChildNodes(node);
} else {
// TODO(sorvell): it's more correct to `Composed.getChildNodes`
// instead of `childNodes` here but any trivial failure
//to use Polymer.dom will result in an error.
return node.childNodes;
}
};


TreeApi.Logical.getParentNode = function(node) {
return node.__dom && node.__dom.parentNode ||
TreeApi.Composed.getParentNode(node);
Expand Down Expand Up @@ -342,6 +309,9 @@
};


// TODO(sorvell): This is largely copy/pasted from the Logical tree
// implementation. The code could be factored such that it could be shared
// but there are perf trade offs to consider.
TreeApi.Composed = {

hasParentNode: function(node) {
Expand All @@ -353,10 +323,20 @@
},

getChildNodes: function(node) {
return node.__dom.$childNodes ||
return this.hasChildNodes(node) ? this._getChildNodes(node) :
(!node.__patched && TreeApi.arrayCopy(node.childNodes));
},

_getChildNodes: function(node) {
if (!node.__dom.$childNodes) {
node.__dom.$childNodes = [];
for (var n=node.__dom.$firstChild; n; n=n.__dom.$nextSibling) {
node.__dom.$childNodes.push(n);
}
}
return node.__dom.$childNodes;
},

getComposedChildNodes: function(node) {
return node.__dom.$childNodes;
},
Expand Down
8 changes: 1 addition & 7 deletions src/mini/shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
if (!this._ownerShadyRoot) {
this._ownerShadyRoot = undefined;
}
// TODO(sorvell): these could be on the domApi object?
// there are a bunch of `__` properties that get put on the node
// from logicalizing. These could be on `__domApi`. Initializing
// them here is problematic because they may have been set prior
// to upgrading.
},

// called as part of content initialization, prior to template stamping
Expand Down Expand Up @@ -421,8 +416,7 @@
// dirty a shadyRoot if a change may trigger reprojection!
function maybeRedistributeParent(content, host) {
// only get logical parent.
var parent = TreeApi.Logical.hasParentNode(content) &&
TreeApi.Logical.getParentNode(content);
var parent = TreeApi.Logical.getParentNode(content);
if (parent && parent.shadyRoot &&
DomApi.hasInsertionPoint(parent.shadyRoot) &&
parent.shadyRoot._distributionClean) {
Expand Down

0 comments on commit 8c95014

Please sign in to comment.