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

Side by Side Diff: samples/third_party/todomvc/web/model.dart

Issue 13872007: Refactor removeRange. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebuild dom. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library model; 5 library model;
6 6
7 import 'package:web_ui/observe.dart'; 7 import 'package:web_ui/observe.dart';
8 import 'package:web_ui/observe/html.dart'; 8 import 'package:web_ui/observe/html.dart';
9 9
10 @observable 10 @observable
(...skipping 11 matching lines...) Expand all
22 // The real model: 22 // The real model:
23 23
24 @observable 24 @observable
25 class AppModel { 25 class AppModel {
26 ObservableList<Todo> todos = new ObservableList<Todo>(); 26 ObservableList<Todo> todos = new ObservableList<Todo>();
27 27
28 // TODO(jmesserly): remove this once List has a remove method. 28 // TODO(jmesserly): remove this once List has a remove method.
29 void removeTodo(Todo todo) { 29 void removeTodo(Todo todo) {
30 var index = todos.indexOf(todo); 30 var index = todos.indexOf(todo);
31 if (index != -1) { 31 if (index != -1) {
32 todos.removeRange(index, 1); 32 todos.removeRange(index, index + 1);
33 } 33 }
34 } 34 }
35 35
36 bool get allChecked => todos.length > 0 && todos.every((t) => t.done); 36 bool get allChecked => todos.length > 0 && todos.every((t) => t.done);
37 37
38 set allChecked(bool value) => todos.forEach((t) { t.done = value; }); 38 set allChecked(bool value) => todos.forEach((t) { t.done = value; });
39 39
40 int get doneCount { 40 int get doneCount {
41 int res = 0; 41 int res = 0;
42 todos.forEach((t) { if (t.done) res++; }); 42 todos.forEach((t) { if (t.done) res++; });
(...skipping 12 matching lines...) Expand all
55 55
56 @observable 56 @observable
57 class Todo { 57 class Todo {
58 String task; 58 String task;
59 bool done = false; 59 bool done = false;
60 60
61 Todo(this.task); 61 Todo(this.task);
62 62
63 String toString() => "$task ${done ? '(done)' : '(not done)'}"; 63 String toString() => "$task ${done ? '(done)' : '(not done)'}";
64 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698