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

Unified Diff: example/todomvc/model.dart

Issue 12225039: Support for observable models, fixes #259 (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: small formatting fixes Created 7 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: example/todomvc/model.dart
diff --git a/example/todomvc/model.dart b/example/todomvc/model.dart
index 7bb52f5ce5528143a1f997010395525ed63657f0..37dc43ae79c1f37fcf96b405a95b1624c51b029b 100644
--- a/example/todomvc/model.dart
+++ b/example/todomvc/model.dart
@@ -4,21 +4,26 @@
library model;
+import 'package:web_ui/observe.dart';
+import 'package:web_ui/observe/html.dart';
+
+@observable
class ViewModel {
bool isVisible(Todo todo) => todo != null &&
((showIncomplete && !todo.done) || (showDone && todo.done));
- bool showIncomplete = true;
+ bool get showIncomplete => locationHash != '#/completed';
- bool showDone = true;
+ bool get showDone => locationHash != '#/active';
}
final ViewModel viewModel = new ViewModel();
// The real model:
+@observable
class AppModel {
- List<Todo> todos = <Todo>[];
+ ObservableList<Todo> todos = new ObservableList<Todo>();
// TODO(jmesserly): remove this once List has a remove method.
void removeTodo(Todo todo) {
@@ -41,12 +46,14 @@ class AppModel {
int get remaining => todos.length - doneCount;
void clearDone() {
- todos = todos.where((t) => !t.done).toList();
+ // TODO(jmesserly): should methods on ObservableList return Observables?
Siggi Cherem (dart-lang) 2013/02/13 01:43:24 Seems reasonable to do so...
Jennifer Messerly 2013/02/13 05:43:15 Yeah. The only tricky bit is what if you want a no
+ todos = new ObservableList.from(todos.where((t) => !t.done));
}
}
final AppModel app = new AppModel();
+@observable
class Todo {
String task;
bool done = false;

Powered by Google App Engine
This is Rietveld 408576698