OLD | NEW |
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 observe.src.change_record; | 5 library observe.src.change_record; |
6 | 6 |
7 import 'package:observe/observe.dart'; | 7 import 'package:observe/observe.dart'; |
8 | 8 |
9 | 9 |
10 /** Records a change to an [Observable]. */ | 10 /** Records a change to an [Observable]. */ |
(...skipping 12 matching lines...) Expand all Loading... |
23 final T oldValue; | 23 final T oldValue; |
24 | 24 |
25 /** The new value of the property. */ | 25 /** The new value of the property. */ |
26 final T newValue; | 26 final T newValue; |
27 | 27 |
28 PropertyChangeRecord(this.object, this.name, this.oldValue, this.newValue); | 28 PropertyChangeRecord(this.object, this.name, this.oldValue, this.newValue); |
29 | 29 |
30 String toString() => | 30 String toString() => |
31 '#<PropertyChangeRecord $name from: $oldValue to: $newValue>'; | 31 '#<PropertyChangeRecord $name from: $oldValue to: $newValue>'; |
32 } | 32 } |
33 | |
34 /** A change record for an observable list. */ | |
35 class ListChangeRecord extends ChangeRecord { | |
36 /** The starting index of the change. */ | |
37 final int index; | |
38 | |
39 /** The number of items removed. */ | |
40 final int removedCount; | |
41 | |
42 /** The number of items added. */ | |
43 final int addedCount; | |
44 | |
45 ListChangeRecord(this.index, {this.removedCount: 0, this.addedCount: 0}) { | |
46 if (addedCount == 0 && removedCount == 0) { | |
47 throw new ArgumentError('added and removed counts should not both be ' | |
48 'zero. Use 1 if this was a single item update.'); | |
49 } | |
50 } | |
51 | |
52 /** Returns true if the provided index was changed by this operation. */ | |
53 bool indexChanged(otherIndex) { | |
54 // If key isn't an int, or before the index, then it wasn't changed. | |
55 if (otherIndex is! int || otherIndex < index) return false; | |
56 | |
57 // If this was a shift operation, anything after index is changed. | |
58 if (addedCount != removedCount) return true; | |
59 | |
60 // Otherwise, anything in the update range was changed. | |
61 return otherIndex < index + addedCount; | |
62 } | |
63 | |
64 String toString() => '#<ListChangeRecord index: $index, ' | |
65 'removed: $removedCount, addedCount: $addedCount>'; | |
66 } | |
OLD | NEW |