| Index: third_party/pkg/angular/demo/todo/web/todo.dart
|
| ===================================================================
|
| --- third_party/pkg/angular/demo/todo/web/todo.dart (revision 33054)
|
| +++ third_party/pkg/angular/demo/todo/web/todo.dart (working copy)
|
| @@ -7,38 +7,24 @@
|
| String text;
|
| bool done;
|
|
|
| - Item([this.text = '', this.done = false]);
|
| + Item([String this.text = '', bool this.done = false]);
|
|
|
| bool get isEmpty => text.isEmpty;
|
|
|
| - Item clone() => new Item(text, done);
|
| + clone() => new Item(text, done);
|
|
|
| - void clear() {
|
| + clear() {
|
| text = '';
|
| done = false;
|
| }
|
| }
|
|
|
| +// In 'server mode', this class fetches items from the server.
|
| +class ServerController {
|
| + Http _http;
|
|
|
| -// ServerController interface. Logic in main.dart determines which
|
| -// implementation we should use.
|
| -abstract class ServerController {
|
| - init(TodoController todo);
|
| -}
|
| + ServerController(Http this._http);
|
|
|
| -
|
| -// 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) {
|
| data.data.forEach((d) {
|
| @@ -48,12 +34,20 @@
|
| }
|
| }
|
|
|
| +// An implementation of ServerController that does nothing.
|
| +// Logic in main.dart determines which implementation we should
|
| +// use.
|
| +class NoServerController implements ServerController {
|
| + init(TodoController todo) { }
|
| +}
|
|
|
| -@NgController(
|
| - selector: '[todo-controller]',
|
| - publishAs: 'todo')
|
| +
|
| +@NgDirective(
|
| + selector: '[todo-controller]',
|
| + publishAs: 'todo'
|
| +)
|
| class TodoController {
|
| - var items = <Item>[];
|
| + List<Item> items;
|
| Item newItem;
|
|
|
| TodoController(ServerController serverController) {
|
| @@ -68,24 +62,33 @@
|
| }
|
|
|
| // workaround for https://github.com/angular/angular.dart/issues/37
|
| - dynamic operator [](String key) => key == 'newItem' ? newItem : null;
|
| + dynamic operator [](String key) {
|
| + if (key == 'newItem') {
|
| + return newItem;
|
| + }
|
| + return null;
|
| + }
|
|
|
| - void add() {
|
| + add() {
|
| if (newItem.isEmpty) return;
|
|
|
| items.add(newItem.clone());
|
| newItem.clear();
|
| }
|
|
|
| - void markAllDone() {
|
| + markAllDone() {
|
| items.forEach((item) => item.done = true);
|
| }
|
|
|
| - void archiveDone() {
|
| + archiveDone() {
|
| items.removeWhere((item) => item.done);
|
| }
|
|
|
| - String classFor(Item item) => item.done ? 'done' : '';
|
| + String classFor(Item item) {
|
| + return item.done ? 'done' : '';
|
| + }
|
|
|
| - int remaining() => items.fold(0, (count, item) => count += item.done ? 0 : 1);
|
| + int remaining() {
|
| + return items.where((item) => !item.done).length;
|
| + }
|
| }
|
|
|