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

Side by Side Diff: pkg/observe/lib/src/change_record.dart

Issue 51483002: fix PathObserver to avoid try+catch (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « pkg/observe/lib/src/change_notifier.dart ('k') | pkg/observe/lib/src/compound_binding.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of observe; 5 library observe.src.change_record;
6
7 import 'package:observe/observe.dart';
8
6 9
7 /** Records a change to an [Observable]. */ 10 /** Records a change to an [Observable]. */
8 // TODO(jmesserly): remove this type 11 // TODO(jmesserly): remove this type
9 abstract class ChangeRecord {} 12 abstract class ChangeRecord {}
10 13
11 /** A change record to a field of an observable object. */ 14 /** A change record to a field of an observable object. */
12 class PropertyChangeRecord<T> extends ChangeRecord { 15 class PropertyChangeRecord<T> extends ChangeRecord {
13 /**
14 * *Deprecated* use [name] instead.
15 * The field that was changed.
16 */
17 @deprecated
18 Symbol get field => name;
19
20 /** The object that changed. */ 16 /** The object that changed. */
21 final object; 17 final object;
22 18
23 /** The name of the property that changed. */ 19 /** The name of the property that changed. */
24 final Symbol name; 20 final Symbol name;
25 21
26 /** The previous value of the property. */ 22 /** The previous value of the property. */
27 final T oldValue; 23 final T oldValue;
28 24
29 /** The new value of the property. */ 25 /** The new value of the property. */
30 final T newValue; 26 final T newValue;
31 27
32 PropertyChangeRecord(this.object, this.name, this.oldValue, this.newValue); 28 PropertyChangeRecord(this.object, this.name, this.oldValue, this.newValue);
33 29
34 /*
35 * *Deprecated* instead of `record.changes(key)` simply do
36 * `key == record.name`.
37 */
38 @deprecated
39 bool changes(key) => key is Symbol && name == key;
40
41 String toString() => 30 String toString() =>
42 '#<PropertyChangeRecord $name from: $oldValue to: $newValue>'; 31 '#<PropertyChangeRecord $name from: $oldValue to: $newValue>';
43 } 32 }
44 33
45 /** A change record for an observable list. */ 34 /** A change record for an observable list. */
46 class ListChangeRecord extends ChangeRecord { 35 class ListChangeRecord extends ChangeRecord {
47 /** The starting index of the change. */ 36 /** The starting index of the change. */
48 final int index; 37 final int index;
49 38
50 /** The number of items removed. */ 39 /** The number of items removed. */
51 final int removedCount; 40 final int removedCount;
52 41
53 /** The number of items added. */ 42 /** The number of items added. */
54 final int addedCount; 43 final int addedCount;
55 44
56 ListChangeRecord(this.index, {this.removedCount: 0, this.addedCount: 0}) { 45 ListChangeRecord(this.index, {this.removedCount: 0, this.addedCount: 0}) {
57 if (addedCount == 0 && removedCount == 0) { 46 if (addedCount == 0 && removedCount == 0) {
58 throw new ArgumentError('added and removed counts should not both be ' 47 throw new ArgumentError('added and removed counts should not both be '
59 'zero. Use 1 if this was a single item update.'); 48 'zero. Use 1 if this was a single item update.');
60 } 49 }
61 } 50 }
62 51
63 /**
64 * *Deprecated* use [indexChanged] instead.
65 * Returns true if the provided index was changed by this operation.
66 */
67 @deprecated
68 bool changes(value) => indexChanged(value);
69
70 /** Returns true if the provided index was changed by this operation. */ 52 /** Returns true if the provided index was changed by this operation. */
71 bool indexChanged(otherIndex) { 53 bool indexChanged(otherIndex) {
72 // If key isn't an int, or before the index, then it wasn't changed. 54 // If key isn't an int, or before the index, then it wasn't changed.
73 if (otherIndex is! int || otherIndex < index) return false; 55 if (otherIndex is! int || otherIndex < index) return false;
74 56
75 // If this was a shift operation, anything after index is changed. 57 // If this was a shift operation, anything after index is changed.
76 if (addedCount != removedCount) return true; 58 if (addedCount != removedCount) return true;
77 59
78 // Otherwise, anything in the update range was changed. 60 // Otherwise, anything in the update range was changed.
79 return otherIndex < index + addedCount; 61 return otherIndex < index + addedCount;
80 } 62 }
81 63
82 String toString() => '#<ListChangeRecord index: $index, ' 64 String toString() => '#<ListChangeRecord index: $index, '
83 'removed: $removedCount, addedCount: $addedCount>'; 65 'removed: $removedCount, addedCount: $addedCount>';
84 } 66 }
OLDNEW
« no previous file with comments | « pkg/observe/lib/src/change_notifier.dart ('k') | pkg/observe/lib/src/compound_binding.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698