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

Unified Diff: third_party/pkg/angular/demo/todo/web/todo.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
« no previous file with comments | « third_party/pkg/angular/demo/todo/web/main.dart ('k') | third_party/pkg/angular/karma-perf.conf.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/pkg/angular/demo/todo/web/todo.dart
diff --git a/third_party/pkg/angular/demo/todo/web/todo.dart b/third_party/pkg/angular/demo/todo/web/todo.dart
index f8cf91edee90fa862863a087375132ad4d8bb6b9..289500a823b82ca359f41ae22df5d9e395ea88b9 100644
--- a/third_party/pkg/angular/demo/todo/web/todo.dart
+++ b/third_party/pkg/angular/demo/todo/web/todo.dart
@@ -7,23 +7,37 @@ class Item {
String text;
bool done;
- Item([String this.text = '', bool this.done = false]);
+ Item([this.text = '', this.done = false]);
bool get isEmpty => text.isEmpty;
- clone() => new Item(text, done);
+ Item clone() => new Item(text, done);
- clear() {
+ void clear() {
text = '';
done = false;
}
}
-// In 'server mode', this class fetches items from the server.
-class ServerController {
- Http _http;
- ServerController(Http this._http);
+// ServerController interface. Logic in main.dart determines which
+// implementation we should use.
+abstract class ServerController {
+ init(TodoController todo);
+}
+
+
+// An implementation of ServerController that does nothing.
+class NoServerController implements ServerController {
+ init(TodoController todo) { }
+}
+
+
+// An implementation of ServerController that fetches items from
+// the server over HTTP.
+class HttpServerController implements ServerController {
+ final Http _http;
+ HttpServerController(this._http);
init(TodoController todo) {
_http(method: 'GET', url: '/todos').then((HttpResponse data) {
@@ -34,20 +48,12 @@ class ServerController {
}
}
-// An implementation of ServerController that does nothing.
-// Logic in main.dart determines which implementation we should
-// use.
-class NoServerController implements ServerController {
- init(TodoController todo) { }
-}
-
-@NgDirective(
- selector: '[todo-controller]',
- publishAs: 'todo'
-)
+@NgController(
+ selector: '[todo-controller]',
+ publishAs: 'todo')
class TodoController {
- List<Item> items;
+ var items = <Item>[];
Item newItem;
TodoController(ServerController serverController) {
@@ -62,33 +68,24 @@ class TodoController {
}
// workaround for https://github.com/angular/angular.dart/issues/37
- dynamic operator [](String key) {
- if (key == 'newItem') {
- return newItem;
- }
- return null;
- }
+ dynamic operator [](String key) => key == 'newItem' ? newItem : null;
- add() {
+ void add() {
if (newItem.isEmpty) return;
items.add(newItem.clone());
newItem.clear();
}
- markAllDone() {
+ void markAllDone() {
items.forEach((item) => item.done = true);
}
- archiveDone() {
+ void archiveDone() {
items.removeWhere((item) => item.done);
}
- String classFor(Item item) {
- return item.done ? 'done' : '';
- }
+ String classFor(Item item) => item.done ? 'done' : '';
- int remaining() {
- return items.where((item) => !item.done).length;
- }
+ int remaining() => items.fold(0, (count, item) => count += item.done ? 0 : 1);
}
« no previous file with comments | « third_party/pkg/angular/demo/todo/web/main.dart ('k') | third_party/pkg/angular/karma-perf.conf.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698