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

Unified Diff: lib/observe/reference.dart

Issue 12225039: Support for observable models, fixes #259 (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: Created 7 years, 10 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/map.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..f44f0a0d80fc7ec1ba26ee47896759258e278291
--- /dev/null
+++ b/lib/observe/reference.dart
@@ -0,0 +1,32 @@
+// 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.
+
+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> {
+ Object _observers;
+ T _value;
+
+ ObservableReference([T initialValue]) : _value = initialValue;
+
+ T get value {
+ if (observeReads) _observers = notifyRead(_observers);
+ return _value;
+ }
+
+ void set value(T newValue) {
+ if (_observers != null && _value != newValue) {
+ _observers = notifyWrite(_observers);
+ }
+ _value = newValue;
+ }
+}
« no previous file with comments | « lib/observe/map.dart ('k') | lib/observe/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698