| 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 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]. The field name for changes is "value". |
| 12 */ |
| 13 class ObservableBox<T> extends ObservableBase { |
| 14 static const _VALUE = const Symbol('value'); |
| 15 |
| 16 T _value; |
| 17 |
| 18 ObservableBox([T initialValue]) : _value = initialValue; |
| 19 |
| 20 T get value => _value; |
| 21 |
| 22 void set value(T newValue) { |
| 23 _value = notifyField(_VALUE, _value, newValue); |
| 24 } |
| 25 |
| 26 String toString() => '#<$runtimeType value: $value>'; |
| 27 |
| 28 getValueWorkaround(key) { |
| 29 if (key == _VALUE) return value; |
| 30 return null; |
| 31 } |
| 32 void setValueWorkaround(key, newValue) { |
| 33 if (key == _VALUE) value = newValue; |
| 34 } |
| 35 } |
| OLD | NEW |