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

Side by Side Diff: samples/simple_todo/todo_model.dart

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
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.md file.
4
5 library todomvc.todo_model;
6
7 // Very simple model for a collection of TODO items.
8
9 class Item {
10 String title;
11 bool _done = false;
12 int _id;
13
14 static int id_pool = 0;
15
16 Item(this.title) {
17 _id = id_pool++;
18 }
19
20 bool get done => _done;
21 void complete() { _done = true; }
22 void uncomplete() { _done = false; }
23 int get id => _id;
24 }
25
26 class TodoModel {
27 Map<int, Item> todos;
28
29 TodoModel() : todos = new Map<int, Item>();
30
31 void createItem(String title) {
32 assert(title.isNotEmpty);
33 Item item = new Item(title);
34 todos.putIfAbsent( item.id, () => item );
35 }
36
37 void deleteItem(int id) {
38 if (todos.containsKey(id)) {
39 todos.remove(id);
40 }
41 }
42
43 void completeItem(int id) {
44 if (todos.containsKey(id)) {
45 todos[id].complete();
46 }
47 }
48
49 void uncompleteItem(int id) {
50 if (todos.containsKey(id)) {
51 todos[id].uncomplete();
52 }
53 }
54
55 void clearItems() {
56 List<int> toDelete = new List<int>();
57
58 todos.forEach((k,v) {
59 if (v.done) {
60 toDelete.add(k);
61 }
62 });
63
64 toDelete.forEach((key) {
65 todos.remove(key);
66 });
67 }
68
69 }
OLDNEW
« no previous file with comments | « samples/simple_todo/simple_todo_service_tests.dart ('k') | samples/todomvc/android/TodoMVC/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698