OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library observe.src.observable; | 5 library observe.src.observable; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 // Note: ObservableProperty is in this list only for the unusual use case of | 10 // Note: ObservableProperty is in this list only for the unusual use case of |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // Register this object for dirty checking purposes. | 75 // Register this object for dirty checking purposes. |
76 registerObservable(this); | 76 registerObservable(this); |
77 | 77 |
78 var mirror = reflect(this); | 78 var mirror = reflect(this); |
79 var values = new Map<Symbol, Object>(); | 79 var values = new Map<Symbol, Object>(); |
80 | 80 |
81 // Note: we scan for @observable regardless of whether the base type | 81 // Note: we scan for @observable regardless of whether the base type |
82 // actually includes this mixin. While perhaps too inclusive, it lets us | 82 // actually includes this mixin. While perhaps too inclusive, it lets us |
83 // avoid complex logic that walks "with" and "implements" clauses. | 83 // avoid complex logic that walks "with" and "implements" clauses. |
84 for (var type = mirror.type; type != objectType; type = type.superclass) { | 84 for (var type = mirror.type; type != objectType; type = type.superclass) { |
85 for (var field in type.declarations.values) { | 85 for (var field in type.variables.values) { |
86 if (field is! VariableMirror || | 86 if (field.isFinal || field.isStatic || field.isPrivate) continue; |
87 field.isFinal || | |
88 field.isStatic || | |
89 field.isPrivate) continue; | |
90 | 87 |
91 for (var meta in field.metadata) { | 88 for (var meta in field.metadata) { |
92 if (meta.reflectee is ObservableProperty) { | 89 if (meta.reflectee is ObservableProperty) { |
93 var name = field.simpleName; | 90 var name = field.simpleName; |
94 // Note: since this is a field, getting the value shouldn't execute | 91 // Note: since this is a field, getting the value shouldn't execute |
95 // user code, so we don't need to worry about errors. | 92 // user code, so we don't need to worry about errors. |
96 values[name] = mirror.getField(name).reflectee; | 93 values[name] = mirror.getField(name).reflectee; |
97 break; | 94 break; |
98 } | 95 } |
99 } | 96 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 Object newValue) { | 195 Object newValue) { |
199 | 196 |
200 if (obj.hasObservers && oldValue != newValue) { | 197 if (obj.hasObservers && oldValue != newValue) { |
201 obj.notifyChange(new PropertyChangeRecord(obj, field, oldValue, newValue)); | 198 obj.notifyChange(new PropertyChangeRecord(obj, field, oldValue, newValue)); |
202 } | 199 } |
203 return newValue; | 200 return newValue; |
204 } | 201 } |
205 | 202 |
206 // NOTE: this is not exported publically. | 203 // NOTE: this is not exported publically. |
207 final objectType = reflectClass(Object); | 204 final objectType = reflectClass(Object); |
OLD | NEW |