-
Notifications
You must be signed in to change notification settings - Fork 248
Methods usable as filters #934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import '../_specs.dart'; | |
import 'package:angular/change_detection/change_detection.dart'; | ||
import 'package:angular/change_detection/dirty_checking_change_detector.dart'; | ||
import 'package:angular/change_detection/dirty_checking_change_detector_static.dart'; | ||
import 'package:angular/change_detection/dirty_checking_change_detector_dynamic.dart'; | ||
import 'dart:collection'; | ||
import 'dart:math'; | ||
|
||
|
@@ -14,19 +15,80 @@ void main() { | |
"first": (o) => o.first, | ||
"age": (o) => o.age, | ||
"last": (o) => o.last, | ||
"toString": (o) => o.toString | ||
"toString": (o) => o.toString, | ||
"isUnderAge": (o) => o.isUnderAge, | ||
"isUnderAgeAsVariable": (o) => o.isUnderAgeAsVariable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. append a "," to avoid diff noise ? |
||
}); | ||
|
||
beforeEach(() { | ||
detector = new DirtyCheckingChangeDetector<String>(getterFactory); | ||
}); | ||
|
||
describe('StaticFieldGetterFactory', () { | ||
DirtyCheckingChangeDetector<String> detector; | ||
var user = new _User('Marko', 'Vuksanovic', 30); | ||
FieldGetterFactory getterFactory = new StaticFieldGetterFactory({ | ||
"first": (o) => o.first, | ||
"age": (o) => o.age, | ||
"last": (o) => o.last, | ||
"toString": (o) => o.toString, | ||
"isUnderAge": (o) => o.isUnderAge, | ||
"isUnderAgeAsVariable": (o) => o.isUnderAgeAsVariable, | ||
"list": (o) => o.list, | ||
"map": (o) => o.map | ||
}); | ||
|
||
beforeEach(() { | ||
detector = new DirtyCheckingChangeDetector<String>(getterFactory); | ||
}); | ||
|
||
it('should detect methods', () { | ||
var obj = new _User(); | ||
expect(getterFactory.isMethod(obj, 'toString')).toEqual(true); | ||
expect(getterFactory.isMethod(obj, 'age')).toEqual(false); | ||
}); | ||
|
||
it('should return true is method is real method', () { | ||
expect(getterFactory.isMethod(user, 'isUnderAge')).toEqual(true); | ||
}); | ||
|
||
it('should return false is field is a function', () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mhevery Should this actually return true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it shouldn't :) |
||
expect(getterFactory.isMethod(user, 'isUnderAgeAsVariable')).toEqual(false); | ||
}); | ||
|
||
it('should return false is field is a list', () { | ||
expect(getterFactory.isMethod(user, 'list')).toEqual(false); | ||
}); | ||
|
||
it('should return false is field is a map', () { | ||
expect(getterFactory.isMethod(user, 'map')).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('Dynamic GetterFactory', () { | ||
DirtyCheckingChangeDetector<String> detector; | ||
var user = new _User('Marko', 'Vuksanovic', 30); | ||
FieldGetterFactory getterFactory = new DynamicFieldGetterFactory(); | ||
|
||
beforeEach(() { | ||
detector = new DirtyCheckingChangeDetector<String>(getterFactory); | ||
}); | ||
|
||
it('should return true is method is real method', () { | ||
expect(getterFactory.isMethod(user, 'isUnderAge')).toEqual(true); | ||
}); | ||
|
||
it('should return false is field is a function', () { | ||
expect(getterFactory.isMethod(user, 'isUnderAgeAsVariable')).toEqual(false); | ||
}); | ||
|
||
it('should return false is field is a list', () { | ||
expect(getterFactory.isMethod(user, 'list')).toEqual(false); | ||
}); | ||
|
||
it('should return false is field is a map', () { | ||
expect(getterFactory.isMethod(user, 'map')).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('object field', () { | ||
|
@@ -657,6 +719,38 @@ void main() { | |
}); | ||
}); | ||
|
||
describe('function watching', () { | ||
it('should detect no changes when watching a function', () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mhevery Does this test align with what you think the behavior should be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes since getting |
||
var user = new _User('marko', 'vuksanovic', 15); | ||
Iterator changeIterator; | ||
|
||
detector..watch(user, 'isUnderAge', null); | ||
changeIterator = detector.collectChanges(); | ||
expect(changeIterator.moveNext()).toEqual(false); | ||
|
||
user.age = 17; | ||
changeIterator = detector.collectChanges(); | ||
expect(changeIterator.moveNext()).toEqual(false); | ||
|
||
user.age = 30; | ||
changeIterator = detector.collectChanges(); | ||
expect(changeIterator.moveNext()).toEqual(false); | ||
}); | ||
|
||
it('should detect change when watching a property function', () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mhevery Is this what you had in mind about changing property functions? |
||
var user = new _User('marko', 'vuksanovic', 30); | ||
Iterator changeIterator; | ||
|
||
detector..watch(user, 'isUnderAgeAsVariable', null); | ||
changeIterator = detector.collectChanges(); | ||
expect(changeIterator.moveNext()).toEqual(false); | ||
|
||
user.isUnderAgeAsVariable = () => false; | ||
changeIterator = detector.collectChanges(); | ||
expect(changeIterator.moveNext()).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('DuplicateMap', () { | ||
DuplicateMap map; | ||
beforeEach(() => map = new DuplicateMap()); | ||
|
@@ -693,8 +787,17 @@ class _User { | |
String first; | ||
String last; | ||
num age; | ||
var isUnderAgeAsVariable; | ||
List<String> list = ['foo', 'bar', 'baz']; | ||
Map map = {'foo': 'bar', 'baz': 'cux'}; | ||
|
||
_User([this.first, this.last, this.age]); | ||
_User([this.first, this.last, this.age]) { | ||
isUnderAgeAsVariable = isUnderAge; | ||
} | ||
|
||
bool isUnderAge() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => |
||
return age != null ? age < 18 : false; | ||
} | ||
} | ||
|
||
Matcher toEqualCollectionRecord({collection, previous, additions, moves, removals}) => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,16 @@ main() { | |
expect(element.querySelectorAll('span').length).toEqual(2); | ||
}); | ||
|
||
it('should support function as a formatter', () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mhevery This should be alternative to the |
||
scope.context['isEven'] = (num) => num % 2 == 0; | ||
var element = compile( | ||
'<div ng-show="true">' | ||
'<span ng-repeat="r in [1, 2, 3, 4] | filter:isEven">{{r}}</span>' | ||
'</div>'); | ||
scope.apply(); | ||
expect(element.text).toEqual('24'); | ||
}); | ||
|
||
|
||
describe('track by', () { | ||
it(r'should track using expression function', () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could a cache make sense here?