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

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

Issue 24076005: fix observing superclass fields, issue 13255 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | « no previous file | pkg/observe/test/observe_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/lib/src/observable.dart
diff --git a/pkg/observe/lib/src/observable.dart b/pkg/observe/lib/src/observable.dart
index 0127d6e0c8525e91529db696d48a1de545d1ccad..d39f84ab96eebd1e6bc73f9bbf921fd5acf71a21 100644
--- a/pkg/observe/lib/src/observable.dart
+++ b/pkg/observe/lib/src/observable.dart
@@ -97,6 +97,8 @@ abstract class ObservableMixin implements Observable {
Map<Symbol, Object> _values;
List<ChangeRecord> _records;
+ static final _objectType = reflectClass(Object);
+
Stream<List<ChangeRecord>> get changes {
if (_changes == null) {
_changes = new StreamController.broadcast(sync: true,
@@ -114,19 +116,21 @@ abstract class ObservableMixin implements Observable {
var mirror = reflect(this);
var values = new Map<Symbol, Object>();
- // TODO(jmesserly): this should consider the superclass. Unfortunately
- // that is not possible right now because of:
- // http://code.google.com/p/dart/issues/detail?id=9434
- for (var field in mirror.type.variables.values) {
- if (field.isFinal || field.isStatic || field.isPrivate) continue;
-
- for (var meta in field.metadata) {
- if (identical(observable, meta.reflectee)) {
- var name = field.simpleName;
- // Note: since this is a field, getting the value shouldn't execute
- // user code, so we don't need to worry about errors.
- values[name] = mirror.getField(name).reflectee;
- break;
+ // Note: we scan for @observable regardless of whether the base type
+ // actually includes this mixin. While perhaps too inclusive, it lets us
+ // avoid complex logic that walks "with" and "implements" clauses.
+ for (var type = mirror.type; type != _objectType; type = type.superclass) {
+ for (var field in type.variables.values) {
+ if (field.isFinal || field.isStatic || field.isPrivate) continue;
+
+ for (var meta in field.metadata) {
+ if (identical(observable, meta.reflectee)) {
+ var name = field.simpleName;
+ // Note: since this is a field, getting the value shouldn't execute
+ // user code, so we don't need to worry about errors.
+ values[name] = mirror.getField(name).reflectee;
+ break;
+ }
}
}
}
« no previous file with comments | « no previous file | pkg/observe/test/observe_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698