| 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 mdv_observe; |
| 6 |
| 7 // TODO(jmesserly): should the property name be configurable? |
| 8 // That would be more convenient. |
| 9 /** |
| 10 * An observable box that holds a value. Use this if you want to store a single |
| 11 * value. For other cases, it is better to use [ObservableList], |
| 12 * [ObservableMap], or a custom [Observable] implementation based on |
| 13 * [ObservableMixin]. The property name for changes is "value". |
| 14 */ |
| 15 class ObservableBox<T> extends ObservableBase { |
| 16 static const _VALUE = const Symbol('value'); |
| 17 |
| 18 T _value; |
| 19 |
| 20 ObservableBox([T initialValue]) : _value = initialValue; |
| 21 |
| 22 T get value => _value; |
| 23 |
| 24 void set value(T newValue) { |
| 25 _value = notifyPropertyChange(_VALUE, _value, newValue); |
| 26 } |
| 27 |
| 28 String toString() => '#<$runtimeType value: $value>'; |
| 29 |
| 30 getValueWorkaround(key) { |
| 31 if (key == _VALUE) return value; |
| 32 return null; |
| 33 } |
| 34 void setValueWorkaround(key, newValue) { |
| 35 if (key == _VALUE) value = newValue; |
| 36 } |
| 37 } |
| OLD | NEW |