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

Unified Diff: third_party/pkg/angular/lib/directive/ng_class.dart

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback 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/directive/ng_class.dart
diff --git a/third_party/pkg/angular/lib/directive/ng_class.dart b/third_party/pkg/angular/lib/directive/ng_class.dart
index b3de27c92b9d4c566357924e730260a9b8c03363..6c77f7302bc873dc776b344b2f55b9bb6df9c012 100644
--- a/third_party/pkg/angular/lib/directive/ng_class.dart
+++ b/third_party/pkg/angular/lib/directive/ng_class.dart
@@ -19,14 +19,28 @@ part of angular.directive;
*
* index.html:
*
- * <p ng-class="{strike: strike, bold: bold, red: red}">Map Syntax Example</p>
+ * <!--
+ * The map syntax:
+ *
+ * ng-class="{key1: value1, key2: value2, ...}"
+ *
+ * results in only adding CSS classes represented by the map keys when
+ * the corresponding value expressions are truthy.
+ *
+ * To use a css class that contains a hyphen (such as line-through in this
+ * example), you should quote the name to make it a valid map key. You
+ * may, of course, quote all the map keys for consistency.
+ * -->
+ * <p ng-class="{'line-through': strike, bold: bold, red: red}">Map Syntax Example</p>
* <input type="checkbox" ng-model="bold"> bold
* <input type="checkbox" ng-model="strike"> strike
* <input type="checkbox" ng-model="red"> red
* <hr>
+ *
* <p ng-class="style">Using String Syntax</p>
* <input type="text" ng-model="style" placeholder="Type: bold strike red">
* <hr>
+ *
* <p ng-class="[style1, style2, style3]">Using Array Syntax</p>
* <input ng-model="style1" placeholder="Type: bold"><br>
* <input ng-model="style2" placeholder="Type: strike"><br>
@@ -37,6 +51,9 @@ part of angular.directive;
* .strike {
* text-decoration: line-through;
* }
+ * .line-through {
+ * text-decoration: line-through;
+ * }
* .bold {
* font-weight: bold;
* }
@@ -50,8 +67,8 @@ part of angular.directive;
map: const {'ng-class': '@valueExpression'},
exportExpressionAttrs: const ['ng-class'])
class NgClassDirective extends _NgClassBase {
- NgClassDirective(dom.Element element, Scope scope, NodeAttrs attrs)
- : super(element, scope, null, attrs);
+ NgClassDirective(dom.Element element, Scope scope, NodeAttrs attrs, AstParser parser)
+ : super(element, scope, null, attrs, parser);
}
/**
@@ -85,8 +102,8 @@ class NgClassDirective extends _NgClassBase {
map: const {'ng-class-odd': '@valueExpression'},
exportExpressionAttrs: const ['ng-class-odd'])
class NgClassOddDirective extends _NgClassBase {
- NgClassOddDirective(dom.Element element, Scope scope, NodeAttrs attrs)
- : super(element, scope, 0, attrs);
+ NgClassOddDirective(dom.Element element, Scope scope, NodeAttrs attrs, AstParser parser)
+ : super(element, scope, 0, attrs, parser);
}
/**
@@ -120,8 +137,8 @@ class NgClassOddDirective extends _NgClassBase {
map: const {'ng-class-even': '@valueExpression'},
exportExpressionAttrs: const ['ng-class-even'])
class NgClassEvenDirective extends _NgClassBase {
- NgClassEvenDirective(dom.Element element, Scope scope, NodeAttrs attrs)
- : super(element, scope, 1, attrs);
+ NgClassEvenDirective(dom.Element element, Scope scope, NodeAttrs attrs, AstParser parser)
+ : super(element, scope, 1, attrs, parser);
}
abstract class _NgClassBase {
@@ -129,16 +146,17 @@ abstract class _NgClassBase {
final Scope scope;
final int mode;
final NodeAttrs nodeAttrs;
+ final AstParser _parser;
var previousSet = [];
var currentSet = [];
- _NgClassBase(this.element, this.scope, this.mode, this.nodeAttrs) {
+ _NgClassBase(this.element, this.scope, this.mode, this.nodeAttrs, this._parser) {
var prevClass;
nodeAttrs.observe('class', (String newValue) {
if (prevClass != newValue) {
prevClass = newValue;
- _handleChange(scope[r'$index']);
+ _handleChange(scope.context[r'$index']);
}
});
}
@@ -146,12 +164,16 @@ abstract class _NgClassBase {
set valueExpression(currentExpression) {
// this should be called only once, so we don't worry about cleaning up
// watcher registrations.
- scope.$watchCollection(currentExpression, (current) {
- currentSet = _flatten(current);
- _handleChange(scope[r'$index']);
- });
+ scope.watch(
+ _parser(currentExpression, collection: true),
+ (current, _) {
+ currentSet = _flatten(current);
+ _handleChange(scope.context[r'$index']);
+ },
+ readOnly: true
+ );
if (mode != null) {
- scope.$watch(r'$index', (index, oldIndex) {
+ scope.watch(_parser(r'$index'), (index, oldIndex) {
var mod = index % 2;
if (oldIndex == null || mod != oldIndex % 2) {
if (mod == mode) {
@@ -160,14 +182,13 @@ abstract class _NgClassBase {
element.classes.removeAll(previousSet);
}
}
- });
+ }, readOnly: true);
}
}
_handleChange(index) {
if (mode == null || (index != null && index % 2 == mode)) {
- element.classes.removeAll(previousSet);
- element.classes.addAll(currentSet);
+ element.classes..removeAll(previousSet)..addAll(currentSet);
}
previousSet = currentSet;
@@ -175,15 +196,20 @@ abstract class _NgClassBase {
static List<String> _flatten(classes) {
if (classes == null) return [];
+ if (classes is CollectionChangeRecord) {
+ classes = (classes as CollectionChangeRecord).iterable.toList();
+ }
if (classes is List) {
- return classes;
+ return classes.where((String e) => e != null && e.isNotEmpty)
+ .toList(growable: false);
+ }
+ if (classes is MapChangeRecord) {
+ classes = (classes as MapChangeRecord).map;
}
if (classes is Map) {
return classes.keys.where((key) => toBool(classes[key])).toList();
}
- if (classes is String) {
- return classes.split(' ');
- }
- throw 'ng-class expects expression value to be List, Map or String.';
+ if (classes is String) return classes.split(' ');
+ throw 'ng-class expects expression value to be List, Map or String, got $classes';
}
}
« no previous file with comments | « third_party/pkg/angular/lib/directive/ng_bind_template.dart ('k') | third_party/pkg/angular/lib/directive/ng_control.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698