Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 474b002

Browse files
committed
fix(change-detection): correctly detect isMethod in StaticFieldGetterFactory
1 parent 39a143d commit 474b002

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/change_detection/dirty_checking_change_detector_static.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class StaticFieldGetterFactory implements FieldGetterFactory {
1212
// We need to know if we are referring to method or field which is a
1313
// function. We can find out by calling it twice and seeing if we get
1414
// the same value. Methods create a new closure each time.
15-
return !identical(getter(object, name), getter(object, name));
15+
FieldGetter getterFn = getter(object, name);
16+
dynamic property = getterFn(object);
17+
return (property is Function) &&
18+
(!identical(property, getterFn(object)));
1619
}
1720

1821
FieldGetter getter(Object object, String name) {

test/change_detection/dirty_checking_change_detector_spec.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ void main() {
1313
FieldGetterFactory getterFactory = new StaticFieldGetterFactory({
1414
"first": (o) => o.first,
1515
"age": (o) => o.age,
16-
"last": (o) => o.last
16+
"last": (o) => o.last,
17+
"toString": (o) => o.toString
1718
});
1819

1920
beforeEach(() {
2021
detector = new DirtyCheckingChangeDetector<String>(getterFactory);
2122
});
2223

24+
describe('StaticFieldGetterFactory', () {
25+
it('should detect methods', () {
26+
var obj = new _User();
27+
expect(getterFactory.isMethod(obj, 'toString')).toEqual(true);
28+
expect(getterFactory.isMethod(obj, 'age')).toEqual(false);
29+
});
30+
});
31+
2332
describe('object field', () {
2433
it('should detect nothing', () {
2534
var changes = detector.collectChanges();

0 commit comments

Comments
 (0)