| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 part of observe; | 5 library observe.src.observable_box; |
| 6 |
| 7 import 'package:observe/observe.dart'; |
| 6 | 8 |
| 7 // TODO(jmesserly): should the property name be configurable? | 9 // TODO(jmesserly): should the property name be configurable? |
| 8 // That would be more convenient. | 10 // That would be more convenient. |
| 9 /** | 11 /** |
| 10 * An observable box that holds a value. Use this if you want to store a single | 12 * 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], | 13 * value. For other cases, it is better to use [ObservableList], |
| 12 * [ObservableMap], or a custom [Observable] implementation based on | 14 * [ObservableMap], or a custom [Observable] implementation based on |
| 13 * [Observable]. The property name for changes is "value". | 15 * [Observable]. The property name for changes is "value". |
| 14 */ | 16 */ |
| 15 class ObservableBox<T> extends ChangeNotifier { | 17 class ObservableBox<T> extends ChangeNotifier { |
| 16 T _value; | 18 T _value; |
| 17 | 19 |
| 18 ObservableBox([T initialValue]) : _value = initialValue; | 20 ObservableBox([T initialValue]) : _value = initialValue; |
| 19 | 21 |
| 20 @reflectable T get value => _value; | 22 @reflectable T get value => _value; |
| 21 | 23 |
| 22 @reflectable void set value(T newValue) { | 24 @reflectable void set value(T newValue) { |
| 23 _value = notifyPropertyChange(#value, _value, newValue); | 25 _value = notifyPropertyChange(#value, _value, newValue); |
| 24 } | 26 } |
| 25 | 27 |
| 26 String toString() => '#<$runtimeType value: $value>'; | 28 String toString() => '#<$runtimeType value: $value>'; |
| 27 } | 29 } |
| OLD | NEW |