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

Unified Diff: pkg/mdv_observe/lib/src/observable_box.dart

Issue 14732003: Implement Model-Driven-Views spec for Dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: try upload again Created 7 years, 7 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
Index: pkg/mdv_observe/lib/src/observable_box.dart
diff --git a/pkg/mdv_observe/lib/src/observable_box.dart b/pkg/mdv_observe/lib/src/observable_box.dart
new file mode 100644
index 0000000000000000000000000000000000000000..484a900f9b7faf66589114b91ef3b84c6ea0f318
--- /dev/null
+++ b/pkg/mdv_observe/lib/src/observable_box.dart
@@ -0,0 +1,37 @@
+// 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.
+
+part of mdv_observe;
+
+// TODO(jmesserly): should the property name be configurable?
+// That would be more convenient.
+/**
+ * An observable box that holds a value. Use this if you want to store a single
+ * value. For other cases, it is better to use [ObservableList],
+ * [ObservableMap], or a custom [Observable] implementation based on
+ * [ObservableMixin]. The property name for changes is "value".
+ */
+class ObservableBox<T> extends ObservableBase {
+ static const _VALUE = const Symbol('value');
+
+ T _value;
+
+ ObservableBox([T initialValue]) : _value = initialValue;
+
+ T get value => _value;
+
+ void set value(T newValue) {
+ _value = notifyPropertyChange(_VALUE, _value, newValue);
+ }
+
+ String toString() => '#<$runtimeType value: $value>';
+
+ getValueWorkaround(key) {
+ if (key == _VALUE) return value;
+ return null;
+ }
+ void setValueWorkaround(key, newValue) {
+ if (key == _VALUE) value = newValue;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698