Skip to content

Commit 4a5d53c

Browse files
pkozlowski-opensourcevsavkin
authored andcommitted
feat: allow using KeyValueChanges as a pipe
1 parent 33b5037 commit 4a5d53c

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

modules/angular2/src/change_detection/pipes/keyvalue_changes.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
2-
32
import {stringify, looseIdentical, isJsObject} from 'angular2/src/facade/lang';
43

5-
export class KeyValueChanges {
4+
import {NO_CHANGE, Pipe} from './pipe';
5+
6+
export class KeyValueChangesFactory {
7+
supports(obj):boolean {
8+
return KeyValueChanges.supportsObj(obj);
9+
}
10+
11+
create():Pipe {
12+
return new KeyValueChanges();
13+
}
14+
}
15+
16+
export class KeyValueChanges extends Pipe {
617
_records:Map;
718

819
_mapHead:KVChangeRecord;
@@ -15,6 +26,7 @@ export class KeyValueChanges {
1526
_removalsTail:KVChangeRecord;
1627

1728
constructor() {
29+
super();
1830
this._records = MapWrapper.create();
1931
this._mapHead = null;
2032
this._previousMapHead = null;
@@ -26,12 +38,20 @@ export class KeyValueChanges {
2638
this._removalsTail = null;
2739
}
2840

29-
static supports(obj):boolean {
41+
static supportsObj(obj):boolean {
3042
return obj instanceof Map || isJsObject(obj);
3143
}
3244

33-
supportsObj(obj):boolean {
34-
return KeyValueChanges.supports(obj);
45+
supports(obj):boolean {
46+
return KeyValueChanges.supportsObj(obj);
47+
}
48+
49+
transform(map){
50+
if (this.check(map)) {
51+
return this;
52+
} else {
53+
return NO_CHANGE;
54+
}
3555
}
3656

3757
get isDirty():boolean {

modules/angular2/test/change_detection/keyvalue_changes_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ export function main() {
131131
if (isJsObject({})) {
132132
describe('JsObject changes', () => {
133133
it('should support JS Object', () => {
134-
expect(KeyValueChanges.supports({})).toBeTruthy();
135-
expect(KeyValueChanges.supports("not supported")).toBeFalsy();
136-
expect(KeyValueChanges.supports(0)).toBeFalsy();
137-
expect(KeyValueChanges.supports(null)).toBeFalsy();
134+
expect(KeyValueChanges.supportsObj({})).toBeTruthy();
135+
expect(KeyValueChanges.supportsObj("not supported")).toBeFalsy();
136+
expect(KeyValueChanges.supportsObj(0)).toBeFalsy();
137+
expect(KeyValueChanges.supportsObj(null)).toBeFalsy();
138138
});
139139

140140
it('should do basic object watching', () => {

0 commit comments

Comments
 (0)