Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: third_party/pkg/angular/lib/core_dom/compiler.dart

Issue 176943008: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/core_dom/compiler.dart
diff --git a/third_party/pkg/angular/lib/core_dom/compiler.dart b/third_party/pkg/angular/lib/core_dom/compiler.dart
index 6d7cda2eacb419fc1bdebd5565f9c855983b6137..6a52ac8d1ceed75eb0ed728f72f150833bd00042 100644
--- a/third_party/pkg/angular/lib/core_dom/compiler.dart
+++ b/third_party/pkg/angular/lib/core_dom/compiler.dart
@@ -2,19 +2,15 @@ part of angular.core.dom;
@NgInjectableService()
class Compiler {
- final DirectiveMap directives;
final Profiler _perf;
final Parser _parser;
final Expando _expando;
- DirectiveSelector selector;
-
- Compiler(this.directives, this._perf, this._parser, this._expando) {
- selector = directiveSelectorFactory(directives);
- }
+ Compiler(this._perf, this._parser, this._expando);
_compileBlock(NodeCursor domCursor, NodeCursor templateCursor,
- List<DirectiveRef> useExistingDirectiveRefs) {
+ List<DirectiveRef> useExistingDirectiveRefs,
+ DirectiveMap directives) {
if (domCursor.nodeList().length == 0) return null;
var directivePositions = null; // don't pre-create to create sparse tree and prevent GC pressure.
@@ -22,7 +18,7 @@ class Compiler {
do {
var declaredDirectiveRefs = useExistingDirectiveRefs == null
- ? selector(domCursor.nodeList()[0])
+ ? directives.selector(domCursor.nodeList()[0])
: useExistingDirectiveRefs;
var children = NgAnnotation.COMPILE_CHILDREN;
var childDirectivePositions = null;
@@ -30,7 +26,7 @@ class Compiler {
cursorAlreadyAdvanced = false;
- for (var j = 0, jj = declaredDirectiveRefs.length; j < jj; j++) {
+ for (var j = 0; j < declaredDirectiveRefs.length; j++) {
DirectiveRef directiveRef = declaredDirectiveRefs[j];
NgAnnotation annotation = directiveRef.annotation;
var blockFactory = null;
@@ -44,13 +40,13 @@ class Compiler {
var remainingDirectives = declaredDirectiveRefs.sublist(j + 1);
blockFactory = compileTransclusion(
domCursor, templateCursor,
- directiveRef, remainingDirectives);
+ directiveRef, remainingDirectives, directives);
- j = jj; // stop processing further directives since they belong to transclusion;
- }
- if (usableDirectiveRefs == null) {
- usableDirectiveRefs = [];
+ // stop processing further directives since they belong to
+ // transclusion
+ j = declaredDirectiveRefs.length;
}
+ if (usableDirectiveRefs == null) usableDirectiveRefs = [];
directiveRef.blockFactory = blockFactory;
createMappings(directiveRef);
usableDirectiveRefs.add(directiveRef);
@@ -59,7 +55,8 @@ class Compiler {
if (children == NgAnnotation.COMPILE_CHILDREN && domCursor.descend()) {
templateCursor.descend();
- childDirectivePositions = _compileBlock(domCursor, templateCursor, null);
+ childDirectivePositions =
+ _compileBlock(domCursor, templateCursor, null, directives);
domCursor.ascend();
templateCursor.ascend();
@@ -82,14 +79,16 @@ class Compiler {
BlockFactory compileTransclusion(
NodeCursor domCursor, NodeCursor templateCursor,
DirectiveRef directiveRef,
- List<DirectiveRef> transcludedDirectiveRefs) {
+ List<DirectiveRef> transcludedDirectiveRefs,
+ DirectiveMap directives) {
var anchorName = directiveRef.annotation.selector + (directiveRef.value != null ? '=' + directiveRef.value : '');
var blockFactory;
var blocks;
var transcludeCursor = templateCursor.replaceWithAnchor(anchorName);
var domCursorIndex = domCursor.index;
- var directivePositions = _compileBlock(domCursor, transcludeCursor, transcludedDirectiveRefs);
+ var directivePositions =
+ _compileBlock(domCursor, transcludeCursor, transcludedDirectiveRefs, directives);
if (directivePositions == null) directivePositions = [];
blockFactory = new BlockFactory(transcludeCursor.elements, directivePositions, _perf, _expando);
@@ -112,14 +111,14 @@ class Compiler {
return blockFactory;
}
- BlockFactory call(List<dom.Node> elements) {
+ BlockFactory call(List<dom.Node> elements, DirectiveMap directives) {
var timerId;
assert((timerId = _perf.startTimer('ng.compile', _html(elements))) != false);
List<dom.Node> domElements = elements;
List<dom.Node> templateElements = cloneElements(domElements);
var directivePositions = _compileBlock(
new NodeCursor(domElements), new NodeCursor(templateElements),
- null);
+ null, directives);
var blockFactory = new BlockFactory(templateElements,
directivePositions == null ? [] : directivePositions, _perf, _expando);
@@ -140,68 +139,91 @@ class Compiler {
var mode = match[1];
var dstPath = match[2];
- Expression dstPathFn = _parser(dstPath.isEmpty ? attrName : dstPath);
+ String dstExpression = dstPath.isEmpty ? attrName : dstPath;
+ Expression dstPathFn = _parser(dstExpression);
if (!dstPathFn.isAssignable) {
throw "Expression '$dstPath' is not assignable in mapping '$mapping' for attribute '$attrName'.";
}
ApplyMapping mappingFn;
switch (mode) {
case '@':
- mappingFn = (NodeAttrs attrs, Scope scope, Object dst) {
- attrs.observe(attrName, (value) => dstPathFn.assign(dst, value));
+ mappingFn = (NodeAttrs attrs, Scope scope, Object controller, FilterMap filters, notify()) {
+ attrs.observe(attrName, (value) {
+ dstPathFn.assign(controller, value);
+ notify();
+ });
};
break;
case '<=>':
- mappingFn = (NodeAttrs attrs, Scope scope, Object dst) {
- if (attrs[attrName] == null) return;
- Expression attrExprFn = _parser(attrs[attrName]);
- var shadowValue = null;
- scope.$watch(
- () => attrExprFn.eval(scope),
- (v) => dstPathFn.assign(dst, shadowValue = v),
- attrs[attrName]);
- if (attrExprFn.isAssignable) {
- scope.$watch(
- () => dstPathFn.eval(dst),
- (v) {
- if (shadowValue != v) {
- shadowValue = v;
- attrExprFn.assign(scope, v);
+ mappingFn = (NodeAttrs attrs, Scope scope, Object controller, FilterMap filters, notify()) {
+ if (attrs[attrName] == null) return notify();
+ String expression = attrs[attrName];
+ Expression expressionFn = _parser(expression);
+ var blockOutbound = false;
+ var blockInbound = false;
+ scope.watch(
+ expression,
+ (inboundValue, _) {
+ if (!blockInbound) {
+ blockOutbound = true;
+ scope.rootScope.runAsync(() => blockOutbound = false);
+ var value = dstPathFn.assign(controller, inboundValue);
+ notify();
+ return value;
+ }
+ },
+ filters: filters
+ );
+ if (expressionFn.isAssignable) {
+ scope.watch(
+ dstExpression,
+ (outboundValue, _) {
+ if (!blockOutbound) {
+ blockInbound = true;
+ scope.rootScope.runAsync(() => blockInbound = false);
+ expressionFn.assign(scope.context, outboundValue);
+ notify();
}
},
- dstPath);
+ context: controller,
+ filters: filters
+ );
}
};
break;
case '=>':
- mappingFn = (NodeAttrs attrs, Scope scope, Object dst) {
- if (attrs[attrName] == null) return;
+ mappingFn = (NodeAttrs attrs, Scope scope, Object controller, FilterMap filters, notify()) {
+ if (attrs[attrName] == null) return notify();
Expression attrExprFn = _parser(attrs[attrName]);
var shadowValue = null;
- scope.$watch(
- () => attrExprFn.eval(scope),
- (v) => dstPathFn.assign(dst, shadowValue = v),
- attrs[attrName]);
+ scope.watch(attrs[attrName],
+ (v, _) {
+ dstPathFn.assign(controller, shadowValue = v);
+ notify();
+ },
+ filters: filters);
};
break;
case '=>!':
- mappingFn = (NodeAttrs attrs, Scope scope, Object dst) {
- if (attrs[attrName] == null) return;
+ mappingFn = (NodeAttrs attrs, Scope scope, Object controller, FilterMap filters, notify()) {
+ if (attrs[attrName] == null) return notify();
Expression attrExprFn = _parser(attrs[attrName]);
- var stopWatching;
- stopWatching = scope.$watch(
- () => attrExprFn.eval(scope),
- (value) {
- if (dstPathFn.assign(dst, value) != null) {
- stopWatching();
+ var watch;
+ watch = scope.watch(
+ attrs[attrName],
+ (value, _) {
+ if (dstPathFn.assign(controller, value) != null) {
+ watch.remove();
}
},
- attrs[attrName]);
+ filters: filters);
+ notify();
};
break;
case '&':
- mappingFn = (NodeAttrs attrs, Scope scope, Object dst) {
- dstPathFn.assign(dst, _parser(attrs[attrName]).bind(scope, ScopeLocals.wrapper));
+ mappingFn = (NodeAttrs attrs, Scope scope, Object dst, FilterMap filters, notify()) {
+ dstPathFn.assign(dst, _parser(attrs[attrName]).bind(scope.context, ScopeLocals.wrapper));
+ notify();
};
break;
}

Powered by Google App Engine
This is Rietveld 408576698