| Index: lib/observe/reference.dart
|
| diff --git a/lib/observe/reference.dart b/lib/observe/reference.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3b12be338e4ccc31fe692a4f07e0d34cc3f2c661
|
| --- /dev/null
|
| +++ b/lib/observe/reference.dart
|
| @@ -0,0 +1,31 @@
|
| +// Copyright (c) 2012, 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.
|
| +
|
| +library web_ui.observe.reference;
|
| +
|
| +import 'package:web_ui/observe.dart';
|
| +
|
| +/**
|
| + * An observable reference to an value. Use this if you want to store a single
|
| + * value. NOTE: it is generally better to use the `@observable` annotation on
|
| + * your observable class. This class is provided for demonstration purposes, or
|
| + * if you happen to need a single unnamed observable reference.
|
| + */
|
| +class ObservableReference<T> extends Observable {
|
| + T _value;
|
| +
|
| + ObservableReference([T initialValue]) : _value = initialValue;
|
| +
|
| + T get value {
|
| + if (observeReads) notifyRead(ChangeRecord.FIELD, 'value');
|
| + return _value;
|
| + }
|
| +
|
| + void set value(T newValue) {
|
| + if (hasObservers) {
|
| + notifyChange(ChangeRecord.FIELD, 'value', _value, newValue);
|
| + }
|
| + _value = newValue;
|
| + }
|
| +}
|
|
|