OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 observable; | 5 library observable; |
6 | 6 |
7 part 'ChangeEvent.dart'; | 7 part 'ChangeEvent.dart'; |
8 part 'EventBatch.dart'; | 8 part 'EventBatch.dart'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ObservableList([Observable parent = null]) | 138 ObservableList([Observable parent = null]) |
139 : super(parent), _internal = new List<T>(); | 139 : super(parent), _internal = new List<T>(); |
140 | 140 |
141 T operator [](int index) => _internal[index]; | 141 T operator [](int index) => _internal[index]; |
142 | 142 |
143 void operator []=(int index, T value) { | 143 void operator []=(int index, T value) { |
144 recordListUpdate(index, value, _internal[index]); | 144 recordListUpdate(index, value, _internal[index]); |
145 _internal[index] = value; | 145 _internal[index] = value; |
146 } | 146 } |
147 | 147 |
| 148 void set last(T value) { |
| 149 if (length == 0) throw new StateError("No element"); |
| 150 int index = length - 1; |
| 151 recordListUpdate(index, value, _internal[index]); |
| 152 _internal[index] = value; |
| 153 } |
| 154 |
148 int get length => _internal.length; | 155 int get length => _internal.length; |
149 | 156 |
150 void set length(int value) { | 157 void set length(int value) { |
151 _internal.length = value; | 158 _internal.length = value; |
152 recordGlobalChange(); | 159 recordGlobalChange(); |
153 } | 160 } |
154 | 161 |
155 void clear() { | 162 void clear() { |
156 _internal.clear(); | 163 _internal.clear(); |
157 recordGlobalChange(); | 164 recordGlobalChange(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // Only fire on an actual change. | 361 // Only fire on an actual change. |
355 if (!identical(newValue, _value)) { | 362 if (!identical(newValue, _value)) { |
356 final oldValue = _value; | 363 final oldValue = _value; |
357 _value = newValue; | 364 _value = newValue; |
358 recordPropertyUpdate("value", newValue, oldValue); | 365 recordPropertyUpdate("value", newValue, oldValue); |
359 } | 366 } |
360 } | 367 } |
361 | 368 |
362 T _value; | 369 T _value; |
363 } | 370 } |
OLD | NEW |