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

Unified Diff: samples/third_party/todomvc/web/model.dart

Issue 76013002: "Reverting 30387" -- failures on IE (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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: samples/third_party/todomvc/web/model.dart
diff --git a/samples/third_party/todomvc/web/model.dart b/samples/third_party/todomvc/web/model.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2f19fcbe49064d8a243e2e303b4feeea4354119f
--- /dev/null
+++ b/samples/third_party/todomvc/web/model.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library todomvc.web.model;
+
+import 'package:polymer/polymer.dart';
+
+final appModel = new AppModel._();
+
+@reflectable
+class AppModel extends Observable {
+ final ObservableList<Todo> todos = new ObservableList<Todo>();
+ @observable int doneCount;
+ @observable int remaining;
+ @observable List<Todo> visibleTodos;
+ @observable bool hasCompleteTodos;
+
+ bool _allChecked;
+
+ AppModel._() {
+ new ListPathObserver(todos, 'done').changes.listen(_updateTodoDone);
+ windowLocation.changes.listen(_updateVisibleTodos);
+ _updateTodoDone(null);
+ }
+
+ _updateTodoDone(_) {
+ // TODO(jmesserly): we should try using Polymer Expressions and filters
+ // instead of computing so many things.
+ doneCount = todos.fold(0, (count, t) => count + (t.done ? 1 : 0));
+ hasCompleteTodos = doneCount > 0;
+ remaining = todos.length - doneCount;
+
+ _allChecked = notifyPropertyChange(const Symbol('allChecked'),
+ _allChecked, todos.length > 0 && remaining == 0);
+
+ _updateVisibleTodos(_);
+ }
+
+ _updateVisibleTodos(_) {
+ bool filterDone = null;
+ if (windowLocation.hash == '#/completed') {
+ filterDone = true;
+ } else if (windowLocation.hash == '#/active') {
+ filterDone = false;
+ }
+
+ visibleTodos = todos.where(
+ (t) => filterDone == null || t.done == filterDone)
+ .toList(growable: false);
+ }
+
+ // TODO(jmesserly): the @observable here is temporary.
+ bool get allChecked => _allChecked;
+ set allChecked(bool value) {
+ todos.forEach((t) { t.done = value; });
+ }
+
+ void clearDone() => todos.removeWhere((t) => t.done);
+}
+
+class Todo extends Observable {
+ @observable String task;
+ @observable bool done = false;
+
+ Todo(this.task);
+
+ String toString() => "$task ${done ? '(done)' : '(not done)'}";
+}
« no previous file with comments | « samples/third_party/todomvc/web/lib-elements/simple_router.html ('k') | samples/third_party/todomvc/web/router_options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698