This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a TreeScope so we can get to the root node in O(1)
- Loading branch information
Showing
11 changed files
with
168 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright 2014 The Polymer Authors. All rights reserved. | ||
* Use of this source code is goverened by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
(function(scope) { | ||
'use strict'; | ||
|
||
/** | ||
* A tree scope represents the root of a tree. All nodes in a tree point to | ||
* the same TreeScope object. The tree scope of a node get set the first time | ||
* it is accessed or when a node is added or remove to a tree. | ||
* @constructor | ||
*/ | ||
function TreeScope(root, parent) { | ||
this.root = root; | ||
this.parent = parent; | ||
} | ||
|
||
TreeScope.prototype = { | ||
get renderer() { | ||
if (this.root instanceof scope.wrappers.ShadowRoot) { | ||
return scope.getRendererForHost(this.root.host); | ||
} | ||
return null; | ||
}, | ||
|
||
contains: function(treeScope) { | ||
for (; treeScope; treeScope = treeScope.parent) { | ||
if (treeScope === this) | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
function setTreeScope(node, treeScope) { | ||
if (node.treeScope_ !== treeScope) { | ||
node.treeScope_ = treeScope; | ||
for (var child = node.firstChild; child; child = child.nextSibling) { | ||
setTreeScope(child, treeScope); | ||
} | ||
} | ||
} | ||
|
||
function getTreeScope(node) { | ||
if (node.treeScope_) | ||
return node.treeScope_; | ||
var parent = node.parentNode; | ||
var treeScope; | ||
if (parent) | ||
treeScope = getTreeScope(parent); | ||
else | ||
treeScope = new TreeScope(node, null); | ||
return node.treeScope_ = treeScope; | ||
} | ||
|
||
scope.TreeScope = TreeScope; | ||
scope.getTreeScope = getTreeScope; | ||
scope.setTreeScope = setTreeScope; | ||
|
||
})(window.ShadowDOMPolyfill); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.