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

Side by Side Diff: samples/tracker/lib/models.dart

Issue 27618002: package:observe fix various api issues (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 tracker.models; 5 library tracker.models;
6 6
7 import 'package:polymer/polymer.dart'; 7 import 'package:polymer/polymer.dart';
8 8
9 final appModel = new Tracker(); 9 final appModel = new Tracker();
10 10
11 /** 11 /**
12 * A model for the tracker app. 12 * A model for the tracker app.
13 * 13 *
14 * [tasks] contains all tasks used in this app. 14 * [tasks] contains all tasks used in this app.
15 */ 15 */
16 class Tracker extends ObservableBase { 16 class Tracker extends Observable {
17 @observable List<Task> tasks; 17 @observable List<Task> tasks;
18 } 18 }
19 19
20 20
21 /** 21 /**
22 * A model for creating a single task. 22 * A model for creating a single task.
23 * 23 *
24 * A task can be saved or unsaved. Only a saved task has a taskID. 24 * A task can be saved or unsaved. Only a saved task has a taskID.
25 * 25 *
26 * This model defines validation rules for a Task. It is the responsibility of 26 * This model defines validation rules for a Task. It is the responsibility of
27 * the view layer to validate a task before assigning a taskID to the task. A 27 * the view layer to validate a task before assigning a taskID to the task. A
28 * task with a taskID is considered saved. 28 * task with a taskID is considered saved.
29 */ 29 */
30 class Task extends ObservableBase { 30 class Task extends Observable {
31 static bool TITLE_REQUIRED = true; 31 static bool TITLE_REQUIRED = true;
32 static const MAX_TITLE_LENGTH = 40; 32 static const MAX_TITLE_LENGTH = 40;
33 static const MAX_DESCRIPTION_LENGTH = 200; 33 static const MAX_DESCRIPTION_LENGTH = 200;
34 static const CURRENT = 'current'; 34 static const CURRENT = 'current';
35 static const PENDING = 'pending'; 35 static const PENDING = 'pending';
36 static const COMPLETED = 'completed'; 36 static const COMPLETED = 'completed';
37 37
38 @observable int taskID; 38 @observable int taskID;
39 @observable String title = ''; 39 @observable String title = '';
40 @observable String description = ''; 40 @observable String description = '';
41 @observable String status = PENDING; 41 @observable String status = PENDING;
42 @observable DateTime createdAt; 42 @observable DateTime createdAt;
43 @observable DateTime updatedAt; 43 @observable DateTime updatedAt;
44 44
45 Task.unsaved(); 45 Task.unsaved();
46 46
47 Task(this.title, this.description, this.status); 47 Task(this.title, this.description, this.status);
48 48
49 bool get isValid { 49 bool get isValid {
50 var minTitleLength = TITLE_REQUIRED ? 1 : 0; 50 var minTitleLength = TITLE_REQUIRED ? 1 : 0;
51 return (title.length >= minTitleLength && 51 return (title.length >= minTitleLength &&
52 title.length < MAX_TITLE_LENGTH && 52 title.length < MAX_TITLE_LENGTH &&
53 description.length < MAX_DESCRIPTION_LENGTH); 53 description.length < MAX_DESCRIPTION_LENGTH);
54 } 54 }
55 55
56 bool get saved => taskID != null; 56 bool get saved => taskID != null;
57 } 57 }
58 58
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698