Chromium Code Reviews| Index: sdk/lib/observe/observable_box.dart |
| diff --git a/sdk/lib/observe/observable_box.dart b/sdk/lib/observe/observable_box.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be177419474b179292c6bb106b59524ef3fe830a |
| --- /dev/null |
| +++ b/sdk/lib/observe/observable_box.dart |
| @@ -0,0 +1,36 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart.observe; |
| + |
| +/** |
| + * An observable box that holds a value. Use this if you want to store a single |
| + * value. For other cases, it is better to use [ObservableList], |
| + * [ObservableMap], or a custom [Observable] implementation based on |
| + * [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
|
| + */ |
| +class ObservableBox<T> extends ObservableMixin { |
| + T _value; |
| + |
| + ObservableBox([T initialValue]) : _value = initialValue; |
| + |
| + T get value => _value; |
| + |
| + void set value(T newValue) { |
| + if (hasObservers) { |
| + notifyChange('value', _value, newValue); |
| + } |
| + _value = newValue; |
| + } |
| + |
| + String toString() => '#<$runtimeType value: $value>'; |
| + |
| + getValue(key) { |
| + if (key == 'value') return value; |
| + return null; |
| + } |
| + void setValue(key, newValue) { |
| + if (key == 'value') value = newValue; |
| + } |
| +} |