Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.observe; | |
| 6 | |
| 7 /** | |
| 8 * An observable box that holds a value. Use this if you want to store a single | |
| 9 * value. For other cases, it is better to use [ObservableList], | |
| 10 * [ObservableMap], or a custom [Observable] implementation based on | |
| 11 * [ObservableMixin]. | |
|
Lasse Reichstein Nielsen
2013/05/06 10:58:58
Document that the key will be the string "value".
Jennifer Messerly
2013/05/07 05:43:38
Done. Also moving this type to package:observe, an
| |
| 12 */ | |
| 13 class ObservableBox<T> extends ObservableMixin { | |
| 14 T _value; | |
| 15 | |
| 16 ObservableBox([T initialValue]) : _value = initialValue; | |
| 17 | |
| 18 T get value => _value; | |
| 19 | |
| 20 void set value(T newValue) { | |
| 21 if (hasObservers) { | |
| 22 notifyChange('value', _value, newValue); | |
| 23 } | |
| 24 _value = newValue; | |
| 25 } | |
| 26 | |
| 27 String toString() => '#<$runtimeType value: $value>'; | |
| 28 | |
| 29 getValue(key) { | |
| 30 if (key == 'value') return value; | |
| 31 return null; | |
| 32 } | |
| 33 void setValue(key, newValue) { | |
| 34 if (key == 'value') value = newValue; | |
| 35 } | |
| 36 } | |
| OLD | NEW |