Skip to content

Commit

Permalink
experiment with pre-patching.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 23, 2015
1 parent a136bc8 commit 5552ef8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
34 changes: 28 additions & 6 deletions src/lib/dom-api-patch.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@
return;
}
patched++;
saveLightChildrenIfNeeded(this.node);
getComposedChildren(this.node);
saveLightChildrenIfNeeded(this.node);
if (!this.node.lightParent) {
this.node.lightParent = this.node.parentNode;
}
if (!this.node._composedParent) {
this.node._composedParent = this.node.parentNode;
}

patchify.patch(this.node);
if (!this.node.__prepatched) {
patchify.patch(this.node);
} else {
patchify.patchAccessor(this.node, 'chidNodes');

This comment has been minimized.

Copy link
@hastebrot

hastebrot Apr 23, 2015

'chidNodes' looks like a typo.

patchify.patchAccessor(this.node, 'parentNode');
}
this.node.__patched = true;

};
Expand Down Expand Up @@ -69,7 +74,13 @@
'firstChild', 'lastChild', 'nextSibling', 'previousSibling',
'firstElementChild', 'lastElementChild',
'nextElementSibling', 'previousElementSibling'
],
],

preAccessors: ['children', 'parentElement',
'firstChild', 'lastChild', 'nextSibling', 'previousSibling',
'firstElementChild', 'lastElementChild',
'nextElementSibling', 'previousElementSibling'
],

writableAccessors: ['textContent', 'innerHTML'],

Expand Down Expand Up @@ -114,6 +125,18 @@
}, this);
},

prePatchObject: function(obj) {
this.methods.forEach(function(m) {
this.patchMethod(obj, m);
}, this);
this.preAccessors.forEach(function(n) {
this.patchAccessor(obj, n, false);
}, this);
this.writableAccessors.forEach(function(n) {
this.patchAccessor(obj, n, true);
}, this);
},

patchMethod: function(obj, name) {
var orig = obj[name];
obj[name] = function() {
Expand Down Expand Up @@ -175,9 +198,8 @@

};

// patchify.patchObject(Polymer.Base);
// delete Polymer.Base.childNodes;
// Polymer.Base.__patched = true;
// patchify.prePatchObject(Polymer.Base);
// Polymer.Base.__prepatched = true;

})();

Expand Down
7 changes: 3 additions & 4 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,11 @@
// actual children will be treated as the rendered state once lightChildren
// is populated.
if (!node.lightChildren) {
var children = [];
for (var child = node.firstChild; child; child = child.nextSibling) {
children.push(child);
var c$ = Array.prototype.slice.call(node.childNodes);
for (var i=0, l=c$.length, child; (i<l) && (child=c$[i]); i++) {
child.lightParent = child.lightParent || node;
}
node.lightChildren = children;
node.lightChildren = c$;
}
}

Expand Down

0 comments on commit 5552ef8

Please sign in to comment.