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

Commit

Permalink
fix(change-detection): correctly detect isMethod in StaticFieldGetter…
Browse files Browse the repository at this point in the history
…Factory
  • Loading branch information
mhevery committed Apr 21, 2014
1 parent 39a143d commit 474b002
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion test/change_detection/dirty_checking_change_detector_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>(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();
Expand Down

0 comments on commit 474b002

Please sign in to comment.