Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions lib/core_dom/tagging_view_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,43 @@ part of angular.core.dom_internal;

var ngViewTag = new UserTag('NgView');

class NodeLinkingInfo {
final bool containsNgBinding;
final bool isElement; // if not, it is a Text or Comment node.
final bool ngBindingChildren;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add comment why do we need this field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would caching the list be more efficient ? It could prevent calling querySelectorAll twice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vicb, no -- NodeLinkingInfo is created by inspecting the template, where _link is operating on clones of the template. They are two sets of nodes which have the same structure.


NodeLinkingInfo(this.containsNgBinding, this.isElement, this.ngBindingChildren);
}

computeNodeLinkingInfos(List<dom.Node> nodeList) {
List<NodeLinkingInfo> list = new List<NodeLinkingInfo>(nodeList.length);

for (int i = 0; i < nodeList.length; i++) {
dom.Node node = nodeList[i];

assert(node.nodeType == dom.Node.ELEMENT_NODE ||
node.nodeType == dom.Node.TEXT_NODE ||
node.nodeType == dom.Node.COMMENT_NODE);

bool isElement = node.nodeType == dom.Node.ELEMENT_NODE;

list[i] = new NodeLinkingInfo(
isElement && node.classes.contains('ng-binding'),
isElement,
isElement && node.querySelectorAll('.ng-binding').length > 0);
}
return list;
}

class TaggingViewFactory implements ViewFactory {
final List<TaggedElementBinder> elementBinders;
final List<dom.Node> templateNodes;
final List<NodeLinkingInfo> nodeLinkingInfos;
final Profiler _perf;

TaggingViewFactory(this.templateNodes, this.elementBinders, this._perf);
TaggingViewFactory(templateNodes, this.elementBinders, this._perf) :
nodeLinkingInfos = computeNodeLinkingInfos(templateNodes),
this.templateNodes = templateNodes;

BoundViewFactory bind(Injector injector) => new BoundViewFactory(this, injector);

Expand Down Expand Up @@ -55,7 +86,8 @@ class TaggingViewFactory implements ViewFactory {

var elementBinderIndex = 0;
for (int i = 0; i < nodeList.length; i++) {
var node = nodeList[i];
dom.Node node = nodeList[i];
NodeLinkingInfo linkingInfo = nodeLinkingInfos[i];

// if node isn't attached to the DOM, create a parent for it.
var parentNode = node.parentNode;
Expand All @@ -66,29 +98,28 @@ class TaggingViewFactory implements ViewFactory {
parentNode.append(node);
}

if (node.nodeType == dom.Node.ELEMENT_NODE) {
var elts = node.querySelectorAll('.ng-binding');
if (linkingInfo.isElement) {
// querySelectorAll doesn't return the node itself
if (node.classes.contains('ng-binding')) {
if (linkingInfo.containsNgBinding) {
var tagged = elementBinders[elementBinderIndex];
_bindTagged(tagged, elementBinderIndex, rootInjector, elementInjectors, view, node);
elementBinderIndex++;
}

for (int j = 0; j < elts.length; j++, elementBinderIndex++) {
TaggedElementBinder tagged = elementBinders[elementBinderIndex];
_bindTagged(tagged, elementBinderIndex, rootInjector, elementInjectors, view, elts[j]);
if (linkingInfo.ngBindingChildren) {
var elts = node.querySelectorAll('.ng-binding');
for (int j = 0; j < elts.length; j++, elementBinderIndex++) {
TaggedElementBinder tagged = elementBinders[elementBinderIndex];
_bindTagged(tagged, elementBinderIndex, rootInjector, elementInjectors, view, elts[j]);
}
}
} else if (node.nodeType == dom.Node.TEXT_NODE ||
node.nodeType == dom.Node.COMMENT_NODE) {
} else {
TaggedElementBinder tagged = elementBinders[elementBinderIndex];
assert(tagged.binder != null || tagged.isTopLevel);
if (tagged.binder != null) {
_bindTagged(tagged, elementBinderIndex, rootInjector, elementInjectors, view, node);
}
elementBinderIndex++;
} else {
throw "nodeType sadness ${node.nodeType}}";
}

if (fakeParent) {
Expand Down