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

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: 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
« no previous file with comments | « example/todomvc/main.dart ('k') | example/todomvc/router_options.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: example/todomvc/model.dart
diff --git a/example/todomvc/model.dart b/example/todomvc/model.dart
index 7bb52f5ce5528143a1f997010395525ed63657f0..f1c7a522c1a2ac88f2791ffc29619421b772593d 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?
+ todos = toObservable(todos.where((t) => !t.done));
}
}
final AppModel app = new AppModel();
+@observable
class Todo {
String task;
bool done = false;
« no previous file with comments | « example/todomvc/main.dart ('k') | example/todomvc/router_options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698