OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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 library web_ui.observe.reference; |
| 6 |
| 7 import 'package:web_ui/observe.dart'; |
| 8 |
| 9 /** |
| 10 * An observable reference to an value. Use this if you want to store a single |
| 11 * value. NOTE: it is generally better to use the `@observable` annotation on |
| 12 * your observable class. This class is provided for demonstration purposes, or |
| 13 * if you happen to need a single unnamed observable reference. |
| 14 */ |
| 15 class ObservableReference<T> extends Observable { |
| 16 T _value; |
| 17 |
| 18 ObservableReference([T initialValue]) : _value = initialValue; |
| 19 |
| 20 T get value { |
| 21 if (observeReads) notifyRead(ChangeRecord.FIELD, 'value'); |
| 22 return _value; |
| 23 } |
| 24 |
| 25 void set value(T newValue) { |
| 26 if (hasObservers) { |
| 27 notifyChange(ChangeRecord.FIELD, 'value', _value, newValue); |
| 28 } |
| 29 _value = newValue; |
| 30 } |
| 31 } |
OLD | NEW |