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

Unified Diff: pkg/observe/lib/src/compound_binding.dart

Issue 19996008: automatically clean up CompoundBinding (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 7 years, 5 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 | « pkg/mdv/lib/src/template_iterator.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/lib/src/compound_binding.dart
diff --git a/pkg/observe/lib/src/compound_binding.dart b/pkg/observe/lib/src/compound_binding.dart
index 80877ce34da0ff7aa57e7c804b03b5a0f011464f..625c82c535a8d6645e88dc50431e2a27e75b9958 100644
--- a/pkg/observe/lib/src/compound_binding.dart
+++ b/pkg/observe/lib/src/compound_binding.dart
@@ -32,10 +32,9 @@ class CompoundBinding extends ChangeNotifierBase {
// TODO(jmesserly): ideally these would be String keys, but sometimes we
// use integers.
- Map<dynamic, StreamSubscription> _bindings = new Map();
+ Map<dynamic, StreamSubscription> _observers = new Map();
Map _values = new Map();
bool _scheduled = false;
- bool _disposed = false;
Object _value;
CompoundBinding([CompoundBindingCombinator combinator]) {
@@ -57,7 +56,7 @@ class CompoundBinding extends ChangeNotifierBase {
get value => _value;
- int get length => _bindings.length;
+ int get length => _observers.length;
void set value(newValue) {
_value = notifyPropertyChange(_VALUE, _value, newValue);
@@ -66,16 +65,16 @@ class CompoundBinding extends ChangeNotifierBase {
void bind(name, model, String path) {
unbind(name);
- // TODO(jmesserly): should we avoid observing until we are observed,
- // similar to PathObserver? Similar for unobserving?
- _bindings[name] = new PathObserver(model, path).bindSync((value) {
+ // TODO(jmesserly): should we delay observing until we are observed,
+ // similar to PathObserver?
+ _observers[name] = new PathObserver(model, path).bindSync((value) {
_values[name] = value;
_scheduleResolve();
});
}
void unbind(name, {bool suppressResolve: false}) {
- var binding = _bindings.remove(name);
+ var binding = _observers.remove(name);
if (binding == null) return;
binding.cancel();
@@ -93,7 +92,7 @@ class CompoundBinding extends ChangeNotifierBase {
}
void resolve() {
- if (_disposed) return;
+ if (_observers.isEmpty) return;
_scheduled = false;
if (_combinator == null) {
@@ -104,14 +103,20 @@ class CompoundBinding extends ChangeNotifierBase {
value = _combinator(_values);
}
- void dispose() {
- for (var binding in _bindings.values) {
+ /**
+ * Closes the observer.
+ *
+ * This happens automatically if the [value] property is no longer observed,
+ * but this can also be called explicitly.
+ */
+ void close() {
+ for (var binding in _observers.values) {
binding.cancel();
}
- _bindings.clear();
+ _observers.clear();
_values.clear();
-
- _disposed = true;
value = null;
}
+
+ _unobserved() => close();
}
« no previous file with comments | « pkg/mdv/lib/src/template_iterator.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698