Skip to content

Commit

Permalink
Merge pull request #75 from PolymerLabs/fixes-72
Browse files Browse the repository at this point in the history
Fixes 72
  • Loading branch information
kevinpschaaf authored Aug 23, 2016
2 parents ed01601 + cfe9487 commit 03d2543
Show file tree
Hide file tree
Showing 17 changed files with 685 additions and 4,693 deletions.
121 changes: 0 additions & 121 deletions src/shady/distributor-v0.html

This file was deleted.

File renamed without changes.
13 changes: 8 additions & 5 deletions src/shady/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
addNode: function(container, node, ref_node) {
var ownerRoot = this.ownerShadyRootForNode(container);
if (ownerRoot) {
// optimization: special insertion point tracking
if (node.__noInsertionPoint) {
ownerRoot._skipUpdateInsertionPoints = true;
}
// note: we always need to see if an insertion point is added
// since this saves logical tree info; however, invalidation state
// needs
var ipAdded = this._maybeAddInsertionPoint(node, container, ownerRoot);
// invalidate insertion points IFF not already invalid!
// TODO(sorvell): this flipped to opt out.
if (!ownerRoot._invalidInsertionPoints) {
ownerRoot._invalidInsertionPoints = ipAdded;
if (ipAdded) {
ownerRoot._skipUpdateInsertionPoints = false;
}
this._addedNode(node, ownerRoot);
}
Expand Down Expand Up @@ -159,7 +162,7 @@
// and forces distribution.
var insertionPointTag = ownerRoot && ownerRoot.getInsertionPointTag() || '';
var fragContent = (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) &&
!node.__noContent &&
!node.__noInsertionPoint &&
insertionPointTag && node.querySelector(insertionPointTag);
var wrappedContent = fragContent &&
(Tree.Logical.getParentNode(fragContent).nodeType !==
Expand Down Expand Up @@ -196,7 +199,7 @@
var added;
var insertionPointTag = root.getInsertionPointTag();
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE &&
!node.__noContent) {
!node.__noInsertionPoint) {
var c$ = node.querySelectorAll(insertionPointTag);
for (var i=0, n, np, na; (i<c$.length) && (n=c$[i]); i++) {
np = Tree.Logical.getParentNode(n);
Expand Down
4 changes: 4 additions & 0 deletions src/shady/patch.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
patchImpl.unpatch(node);
};

ShadyDom.isPatched = function(node) {
return Boolean(node.__patched);
}

var log = false;

var patchImpl = {
Expand Down
42 changes: 27 additions & 15 deletions src/shady/shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@
<!-- TODO(sorvell): notification...
<!-- <link rel="import" href="lib/dom-api-effective-nodes-observer.html"> -->
<!-- <link rel="import" href="lib/dom-api-distributed-nodes-observer.html"> -->
<link rel="import" href="distributor-v1.html">
<link rel="import" href="distributor-v0.html">
<link rel="import" href="distributor.html">
<link rel="import" href="patch.html">
<link rel="import" href="flush.html">
<script>

(function() {

var Tree = ShadyDom.Tree;

/**
Implements a pared down version of ShadowDOM's scoping, which is easy to
polyfill across browsers.
*/
class ShadyRoot {

constructor(host, useV0) {
if (!host) {
throw 'Must provide a host';
Expand Down Expand Up @@ -57,16 +56,17 @@
Tree.Logical.saveChildNodes(this);
// state flags
this._clean = true;
this._hasDistributed = false;
this._distributor = useV0 ?
new ShadyDom.DistributorV0(this) :
this._hasRendered = false;
this._distributor = useV0 ?
new ShadyDom.DistributorV0(this) :
new ShadyDom.DistributorV1(this);
this.update();
// TODO(sorvell): without calling update here,
// initial distribution will not occur unless an element has been
// TODO(sorvell): host state flags were set here next, needed?
},

// async render the "top" distributor (this is all that is needed to
// async render the "top" distributor (this is all that is needed to
// distribute this host.
update: function() {
var distributionRoot = this._findDistributionRoot(this.host);
Expand Down Expand Up @@ -115,17 +115,32 @@
this._renderDebouncer = null;
}
if (!this._clean) {
// TODO(sorvell): updating insertion points is $ so optable
if (!this._skipUpdateInsertionPoints) {
this.updateInsertionPoints();
} else if (!this._hasRendered) {
this._insertionPoints = [];
}
this._skipUpdateInsertionPoints = false;
// TODO(sorvell): previous ShadyDom had a fast path here
// that would avoid distribution for initial render if
// no insertion points exist. We cannot currently do this because
// it relies on elements being in the physical shadowRoot element
// so that native methods will be used. The current append code
// simply provokes distribution in this case and does not put the
// nodes in the shadowRoot. This could be done but we'll need to
// consider if the special processing is worth the perf gain.
// if (!this._hasRendered && !this._insertionPoints.length) {
// Tree.Composed.clearChildNodes(this.host);
// Tree.Composed.appendChild(this.host, this);
// } else {
// logical
this.distribute();
// physical
this.compose();
// allow distributor to do post render tasks (e.g. fire events!)
this._distributor.rendered();
this._clean = true;
this._hasRendered = true;
}
},

Expand Down Expand Up @@ -181,13 +196,9 @@
// which informs effective children observers
//notifyContentObservers(this);
// TODO(sorvell): See fast paths here in Polymer v1
// (these seem unnecessary)
// (these seem unnecessary)
// NOTE: send a signal to any observers
// to report the initial set of childNodes
if (!this._hasDistributed) {
//notifyInitialDistribution(this.host);
}
this._hasDistributed = true;
},

// Reify dom such that it is at its correct rendering position
Expand All @@ -210,7 +221,8 @@
for (var i = 0; i < c$.length; i++) {
var child = c$[i];
if (this._distributor.isInsertionPoint(child)) {
var distributedNodes = child._distributedNodes;
var distributedNodes = child._distributedNodes ||
(child._distributedNodes = []);
for (var j = 0; j < distributedNodes.length; j++) {
var distributedNode = distributedNodes[j];
if (this.isFinalDestination(child, distributedNode)) {
Expand Down
Loading

0 comments on commit 03d2543

Please sign in to comment.