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

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

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://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/directive/ng_class.dart
===================================================================
--- third_party/pkg/angular/lib/directive/ng_class.dart (revision 33054)
+++ third_party/pkg/angular/lib/directive/ng_class.dart (working copy)
@@ -19,28 +19,14 @@
*
* index.html:
*
- * <!--
- * 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>
+ * <p ng-class="{strike: 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>
@@ -51,9 +37,6 @@
* .strike {
* text-decoration: line-through;
* }
- * .line-through {
- * text-decoration: line-through;
- * }
* .bold {
* font-weight: bold;
* }
@@ -67,8 +50,8 @@
map: const {'ng-class': '@valueExpression'},
exportExpressionAttrs: const ['ng-class'])
class NgClassDirective extends _NgClassBase {
- NgClassDirective(dom.Element element, Scope scope, NodeAttrs attrs, AstParser parser)
- : super(element, scope, null, attrs, parser);
+ NgClassDirective(dom.Element element, Scope scope, NodeAttrs attrs)
+ : super(element, scope, null, attrs);
}
/**
@@ -102,8 +85,8 @@
map: const {'ng-class-odd': '@valueExpression'},
exportExpressionAttrs: const ['ng-class-odd'])
class NgClassOddDirective extends _NgClassBase {
- NgClassOddDirective(dom.Element element, Scope scope, NodeAttrs attrs, AstParser parser)
- : super(element, scope, 0, attrs, parser);
+ NgClassOddDirective(dom.Element element, Scope scope, NodeAttrs attrs)
+ : super(element, scope, 0, attrs);
}
/**
@@ -137,8 +120,8 @@
map: const {'ng-class-even': '@valueExpression'},
exportExpressionAttrs: const ['ng-class-even'])
class NgClassEvenDirective extends _NgClassBase {
- NgClassEvenDirective(dom.Element element, Scope scope, NodeAttrs attrs, AstParser parser)
- : super(element, scope, 1, attrs, parser);
+ NgClassEvenDirective(dom.Element element, Scope scope, NodeAttrs attrs)
+ : super(element, scope, 1, attrs);
}
abstract class _NgClassBase {
@@ -146,17 +129,16 @@
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, this._parser) {
+ _NgClassBase(this.element, this.scope, this.mode, this.nodeAttrs) {
var prevClass;
nodeAttrs.observe('class', (String newValue) {
if (prevClass != newValue) {
prevClass = newValue;
- _handleChange(scope.context[r'$index']);
+ _handleChange(scope[r'$index']);
}
});
}
@@ -164,16 +146,12 @@
set valueExpression(currentExpression) {
// this should be called only once, so we don't worry about cleaning up
// watcher registrations.
- scope.watch(
- _parser(currentExpression, collection: true),
- (current, _) {
- currentSet = _flatten(current);
- _handleChange(scope.context[r'$index']);
- },
- readOnly: true
- );
+ scope.$watchCollection(currentExpression, (current) {
+ currentSet = _flatten(current);
+ _handleChange(scope[r'$index']);
+ });
if (mode != null) {
- scope.watch(_parser(r'$index'), (index, oldIndex) {
+ scope.$watch(r'$index', (index, oldIndex) {
var mod = index % 2;
if (oldIndex == null || mod != oldIndex % 2) {
if (mod == mode) {
@@ -182,13 +160,14 @@
element.classes.removeAll(previousSet);
}
}
- }, readOnly: true);
+ });
}
}
_handleChange(index) {
if (mode == null || (index != null && index % 2 == mode)) {
- element.classes..removeAll(previousSet)..addAll(currentSet);
+ element.classes.removeAll(previousSet);
+ element.classes.addAll(currentSet);
}
previousSet = currentSet;
@@ -196,20 +175,15 @@
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.where((String e) => e != null && e.isNotEmpty)
- .toList(growable: false);
+ return classes;
}
- 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, got $classes';
+ if (classes is String) {
+ return classes.split(' ');
+ }
+ throw 'ng-class expects expression value to be List, Map or String.';
}
}
« 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