feat: allow using KeyValueChanges as a pipe
This commit is contained in:
parent
33b503720a
commit
4a5d53c549
|
@ -1,8 +1,19 @@
|
|||
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {stringify, looseIdentical, isJsObject} from 'angular2/src/facade/lang';
|
||||
|
||||
export class KeyValueChanges {
|
||||
import {NO_CHANGE, Pipe} from './pipe';
|
||||
|
||||
export class KeyValueChangesFactory {
|
||||
supports(obj):boolean {
|
||||
return KeyValueChanges.supportsObj(obj);
|
||||
}
|
||||
|
||||
create():Pipe {
|
||||
return new KeyValueChanges();
|
||||
}
|
||||
}
|
||||
|
||||
export class KeyValueChanges extends Pipe {
|
||||
_records:Map;
|
||||
|
||||
_mapHead:KVChangeRecord;
|
||||
|
@ -15,6 +26,7 @@ export class KeyValueChanges {
|
|||
_removalsTail:KVChangeRecord;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._records = MapWrapper.create();
|
||||
this._mapHead = null;
|
||||
this._previousMapHead = null;
|
||||
|
@ -26,12 +38,20 @@ export class KeyValueChanges {
|
|||
this._removalsTail = null;
|
||||
}
|
||||
|
||||
static supports(obj):boolean {
|
||||
static supportsObj(obj):boolean {
|
||||
return obj instanceof Map || isJsObject(obj);
|
||||
}
|
||||
|
||||
supportsObj(obj):boolean {
|
||||
return KeyValueChanges.supports(obj);
|
||||
supports(obj):boolean {
|
||||
return KeyValueChanges.supportsObj(obj);
|
||||
}
|
||||
|
||||
transform(map){
|
||||
if (this.check(map)) {
|
||||
return this;
|
||||
} else {
|
||||
return NO_CHANGE;
|
||||
}
|
||||
}
|
||||
|
||||
get isDirty():boolean {
|
||||
|
|
|
@ -131,10 +131,10 @@ export function main() {
|
|||
if (isJsObject({})) {
|
||||
describe('JsObject changes', () => {
|
||||
it('should support JS Object', () => {
|
||||
expect(KeyValueChanges.supports({})).toBeTruthy();
|
||||
expect(KeyValueChanges.supports("not supported")).toBeFalsy();
|
||||
expect(KeyValueChanges.supports(0)).toBeFalsy();
|
||||
expect(KeyValueChanges.supports(null)).toBeFalsy();
|
||||
expect(KeyValueChanges.supportsObj({})).toBeTruthy();
|
||||
expect(KeyValueChanges.supportsObj("not supported")).toBeFalsy();
|
||||
expect(KeyValueChanges.supportsObj(0)).toBeFalsy();
|
||||
expect(KeyValueChanges.supportsObj(null)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should do basic object watching', () => {
|
||||
|
|
Loading…
Reference in New Issue