diff --git a/lib/change_detection/dirty_checking_change_detector_static.dart b/lib/change_detection/dirty_checking_change_detector_static.dart index a7b8c1200..66bd245f7 100644 --- a/lib/change_detection/dirty_checking_change_detector_static.dart +++ b/lib/change_detection/dirty_checking_change_detector_static.dart @@ -12,7 +12,10 @@ class StaticFieldGetterFactory implements FieldGetterFactory { // We need to know if we are referring to method or field which is a // function. We can find out by calling it twice and seeing if we get // the same value. Methods create a new closure each time. - return !identical(getter(object, name), getter(object, name)); + FieldGetter getterFn = getter(object, name); + dynamic property = getterFn(object); + return (property is Function) && + (!identical(property, getterFn(object))); } FieldGetter getter(Object object, String name) { diff --git a/test/change_detection/dirty_checking_change_detector_spec.dart b/test/change_detection/dirty_checking_change_detector_spec.dart index 6eabf1d28..06dc50baa 100644 --- a/test/change_detection/dirty_checking_change_detector_spec.dart +++ b/test/change_detection/dirty_checking_change_detector_spec.dart @@ -13,13 +13,22 @@ void main() { FieldGetterFactory getterFactory = new StaticFieldGetterFactory({ "first": (o) => o.first, "age": (o) => o.age, - "last": (o) => o.last + "last": (o) => o.last, + "toString": (o) => o.toString }); beforeEach(() { detector = new DirtyCheckingChangeDetector(getterFactory); }); + describe('StaticFieldGetterFactory', () { + it('should detect methods', () { + var obj = new _User(); + expect(getterFactory.isMethod(obj, 'toString')).toEqual(true); + expect(getterFactory.isMethod(obj, 'age')).toEqual(false); + }); + }); + describe('object field', () { it('should detect nothing', () { var changes = detector.collectChanges();