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 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> { |
| 16 Object _observers; |
| 17 T _value; |
| 18 |
| 19 ObservableReference([T initialValue]) : _value = initialValue; |
| 20 |
| 21 T get value { |
| 22 if (observeReads) _observers = notifyRead(_observers); |
| 23 return _value; |
| 24 } |
| 25 |
| 26 void set value(T newValue) { |
| 27 if (_observers != null && _value != newValue) { |
| 28 _observers = notifyWrite(_observers); |
| 29 } |
| 30 _value = newValue; |
| 31 } |
| 32 } |
OLD | NEW |