Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Unified Diff: lib/observe/reference.dart

Issue 12096106: work in progress: observable implementation using detailed change records (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/observe/observable.dart ('k') | lib/observe/set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
+}
« no previous file with comments | « lib/observe/observable.dart ('k') | lib/observe/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698