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 import 'dart:coreimpl'; | 7 import 'dart:coreimpl'; |
8 | 8 |
9 part 'ChangeEvent.dart'; | 9 part 'ChangeEvent.dart'; |
10 part 'EventBatch.dart'; | 10 part 'EventBatch.dart'; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 recordListRemove(index, found); | 208 recordListRemove(index, found); |
209 } | 209 } |
210 return found; | 210 return found; |
211 } | 211 } |
212 | 212 |
213 int indexOf(T element, [int start = 0]) { | 213 int indexOf(T element, [int start = 0]) { |
214 return _internal.indexOf(element, start); | 214 return _internal.indexOf(element, start); |
215 } | 215 } |
216 | 216 |
217 int lastIndexOf(T element, [int start = null]) { | 217 int lastIndexOf(T element, [int start = null]) { |
218 if (start === null) start = length - 1; | 218 if (start == null) start = length - 1; |
219 return _internal.lastIndexOf(element, start); | 219 return _internal.lastIndexOf(element, start); |
220 } | 220 } |
221 | 221 |
222 bool removeFirstElement(T element) { | 222 bool removeFirstElement(T element) { |
223 // the removeAt above will record the event. | 223 // the removeAt above will record the event. |
224 return (removeAt(indexOf(element, 0)) != null); | 224 return (removeAt(indexOf(element, 0)) != null); |
225 } | 225 } |
226 | 226 |
227 int removeAllElements(T element) { | 227 int removeAllElements(T element) { |
228 int count = 0; | 228 int count = 0; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 class ObservableValue<T> extends AbstractObservable { | 280 class ObservableValue<T> extends AbstractObservable { |
281 ObservableValue(T value, [Observable parent = null]) | 281 ObservableValue(T value, [Observable parent = null]) |
282 : super(parent), _value = value; | 282 : super(parent), _value = value; |
283 | 283 |
284 T get value => _value; | 284 T get value => _value; |
285 | 285 |
286 void set value(T newValue) { | 286 void set value(T newValue) { |
287 // Only fire on an actual change. | 287 // Only fire on an actual change. |
288 // TODO(terry): An object identity test === is needed. Each DataSource has | 288 // TODO(terry): An object identity test === is needed. Each DataSource has |
289 // its own operator == which does a value compare. Which | 289 // its own operator == which does a value compare. Which |
290 // equality check should be done? | 290 // equality check should be done? |
Lasse Reichstein Nielsen
2012/11/12 13:10:41
Remove comment. Using identical seems the right th
floitsch
2012/11/12 22:18:43
Done.
| |
291 if (newValue !== _value) { | 291 if (!identical(newValue, _value)) { |
292 final oldValue = _value; | 292 final oldValue = _value; |
293 _value = newValue; | 293 _value = newValue; |
294 recordPropertyUpdate("value", newValue, oldValue); | 294 recordPropertyUpdate("value", newValue, oldValue); |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 T _value; | 298 T _value; |
299 } | 299 } |
OLD | NEW |