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

Commit 0cc50bc

Browse files
committed
revert(DCCD): Reverts method closurization changes.
revert(DCCD): Reverts "when watching variables, always fire on first digest" This reverts commit 50fc615. revert(ChangeDetector): Reverts "When watching a methods colorization should not show up as changes" This reverts commit 3bc5ec9.
1 parent be1f6b0 commit 0cc50bc

File tree

4 files changed

+10
-132
lines changed

4 files changed

+10
-132
lines changed

lib/change_detection/dirty_checking_change_detector.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,8 @@ class DirtyCheckingRecord<H> implements Record<H>, WatchRecord<H> {
460460
_mode = _MODE_MAP_FIELD_;
461461
_getter = null;
462462
} else {
463-
if (_fieldGetterFactory.isMethod(obj, field)) {
464-
_mode = _MODE_IDENTITY_;
465-
previousValue = currentValue = _fieldGetterFactory.method(obj, field)(obj);
466-
assert(previousValue is Function);
467-
} else {
468-
_mode = _MODE_GETTER_;
469-
_getter = _fieldGetterFactory.getter(obj, field);
470-
}
463+
_mode = _MODE_GETTER_;
464+
_getter = _fieldGetterFactory.getter(obj, field);
471465
}
472466
}
473467

lib/change_detection/dirty_checking_change_detector_dynamic.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import 'dart:mirrors';
1313
class DynamicFieldGetterFactory implements FieldGetterFactory {
1414
final isMethodInvoke = true;
1515

16-
isMethod(Object object, String name) {
17-
var declaration = reflectClass(object.runtimeType).declarations[new Symbol(name)];
18-
return declaration != null &&
19-
declaration is MethodMirror &&
20-
(declaration as MethodMirror).isRegularMethod;
16+
bool isMethod(Object object, String name) {
17+
try {
18+
return method(object, name) != null;
19+
} catch (e, s) {
20+
return false;
21+
}
2122
}
2223

2324
Function method(Object object, String name) {

test/change_detection/dirty_checking_change_detector_spec.dart

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import '../_specs.dart';
44
import 'package:angular/change_detection/change_detection.dart';
55
import 'package:angular/change_detection/dirty_checking_change_detector.dart';
66
import 'package:angular/change_detection/dirty_checking_change_detector_static.dart';
7-
import 'package:angular/change_detection/dirty_checking_change_detector_dynamic.dart';
87
import 'dart:collection';
98
import 'dart:math';
109

@@ -15,80 +14,19 @@ void main() {
1514
"first": (o) => o.first,
1615
"age": (o) => o.age,
1716
"last": (o) => o.last,
18-
"toString": (o) => o.toString,
19-
"isUnderAge": (o) => o.isUnderAge,
20-
"isUnderAgeAsVariable": (o) => o.isUnderAgeAsVariable
17+
"toString": (o) => o.toString
2118
});
2219

2320
beforeEach(() {
2421
detector = new DirtyCheckingChangeDetector<String>(getterFactory);
2522
});
2623

2724
describe('StaticFieldGetterFactory', () {
28-
DirtyCheckingChangeDetector<String> detector;
29-
var user = new _User('Marko', 'Vuksanovic', 30);
30-
FieldGetterFactory getterFactory = new StaticFieldGetterFactory({
31-
"first": (o) => o.first,
32-
"age": (o) => o.age,
33-
"last": (o) => o.last,
34-
"toString": (o) => o.toString,
35-
"isUnderAge": (o) => o.isUnderAge,
36-
"isUnderAgeAsVariable": (o) => o.isUnderAgeAsVariable,
37-
"list": (o) => o.list,
38-
"map": (o) => o.map
39-
});
40-
41-
beforeEach(() {
42-
detector = new DirtyCheckingChangeDetector<String>(getterFactory);
43-
});
44-
4525
it('should detect methods', () {
4626
var obj = new _User();
4727
expect(getterFactory.isMethod(obj, 'toString')).toEqual(true);
4828
expect(getterFactory.isMethod(obj, 'age')).toEqual(false);
4929
});
50-
51-
it('should return true is method is real method', () {
52-
expect(getterFactory.isMethod(user, 'isUnderAge')).toEqual(true);
53-
});
54-
55-
it('should return false is field is a function', () {
56-
expect(getterFactory.isMethod(user, 'isUnderAgeAsVariable')).toEqual(false);
57-
});
58-
59-
it('should return false is field is a list', () {
60-
expect(getterFactory.isMethod(user, 'list')).toEqual(false);
61-
});
62-
63-
it('should return false is field is a map', () {
64-
expect(getterFactory.isMethod(user, 'map')).toEqual(false);
65-
});
66-
});
67-
68-
describe('Dynamic GetterFactory', () {
69-
DirtyCheckingChangeDetector<String> detector;
70-
var user = new _User('Marko', 'Vuksanovic', 30);
71-
FieldGetterFactory getterFactory = new DynamicFieldGetterFactory();
72-
73-
beforeEach(() {
74-
detector = new DirtyCheckingChangeDetector<String>(getterFactory);
75-
});
76-
77-
it('should return true is method is real method', () {
78-
expect(getterFactory.isMethod(user, 'isUnderAge')).toEqual(true);
79-
});
80-
81-
it('should return false is field is a function', () {
82-
expect(getterFactory.isMethod(user, 'isUnderAgeAsVariable')).toEqual(false);
83-
});
84-
85-
it('should return false is field is a list', () {
86-
expect(getterFactory.isMethod(user, 'list')).toEqual(false);
87-
});
88-
89-
it('should return false is field is a map', () {
90-
expect(getterFactory.isMethod(user, 'map')).toEqual(false);
91-
});
9230
});
9331

9432
describe('object field', () {
@@ -719,42 +657,6 @@ void main() {
719657
});
720658
});
721659

722-
describe('function watching', () {
723-
it('should detect no changes when watching a function', () {
724-
var user = new _User('marko', 'vuksanovic', 15);
725-
Iterator changeIterator;
726-
727-
detector..watch(user, 'isUnderAge', null);
728-
changeIterator = detector.collectChanges();
729-
expect(changeIterator.moveNext()).toEqual(true);
730-
expect(changeIterator.moveNext()).toEqual(false);
731-
732-
user.age = 17;
733-
changeIterator = detector.collectChanges();
734-
expect(changeIterator.moveNext()).toEqual(false);
735-
736-
user.age = 30;
737-
changeIterator = detector.collectChanges();
738-
expect(changeIterator.moveNext()).toEqual(false);
739-
});
740-
741-
it('should detect change when watching a property function', () {
742-
var user = new _User('marko', 'vuksanovic', 30);
743-
Iterator changeIterator;
744-
745-
detector..watch(user, 'isUnderAgeAsVariable', null);
746-
changeIterator = detector.collectChanges();
747-
expect(changeIterator.moveNext()).toEqual(true);
748-
749-
changeIterator = detector.collectChanges();
750-
expect(changeIterator.moveNext()).toEqual(false);
751-
752-
user.isUnderAgeAsVariable = () => false;
753-
changeIterator = detector.collectChanges();
754-
expect(changeIterator.moveNext()).toEqual(true);
755-
});
756-
});
757-
758660
describe('DuplicateMap', () {
759661
DuplicateMap map;
760662
beforeEach(() => map = new DuplicateMap());
@@ -791,17 +693,8 @@ class _User {
791693
String first;
792694
String last;
793695
num age;
794-
var isUnderAgeAsVariable;
795-
List<String> list = ['foo', 'bar', 'baz'];
796-
Map map = {'foo': 'bar', 'baz': 'cux'};
797696

798-
_User([this.first, this.last, this.age]) {
799-
isUnderAgeAsVariable = isUnderAge;
800-
}
801-
802-
bool isUnderAge() {
803-
return age != null ? age < 18 : false;
804-
}
697+
_User([this.first, this.last, this.age]);
805698
}
806699

807700
Matcher toEqualCollectionRecord({collection, previous, additions, moves, removals}) =>

test/directive/ng_repeat_spec.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ main() {
116116
expect(element.querySelectorAll('span').length).toEqual(2);
117117
});
118118

119-
it('should support function as a formatter', () {
120-
scope.context['isEven'] = (num) => num % 2 == 0;
121-
var element = compile(
122-
'<div ng-show="true">'
123-
'<span ng-repeat="r in [1, 2] | filter:isEven">{{r}}</span>'
124-
'</div>');
125-
scope.apply();
126-
expect(element.text).toEqual('2');
127-
});
128-
129119

130120
describe('track by', () {
131121
it(r'should track using expression function', () {

0 commit comments

Comments
 (0)