refactor: add types to top-level fields in change_detection

Also introduced an abstract PipeFactory base class
This commit is contained in:
Kevin Moore 2015-05-04 12:18:06 -07:00
parent 740d85cad8
commit f5b56c627b
6 changed files with 59 additions and 16 deletions

View File

@ -1,4 +1,5 @@
import {DynamicProtoChangeDetector, JitProtoChangeDetector} from './proto_change_detector';
import {PipeFactory} from './pipes/pipe';
import {PipeRegistry} from './pipes/pipe_registry';
import {IterableChangesFactory} from './pipes/iterable_changes';
import {KeyValueChangesFactory} from './pipes/keyvalue_changes';
@ -16,7 +17,7 @@ import {List} from 'angular2/src/facade/collection';
*
* @exportedAs angular2/pipes
*/
export var keyValDiff = [
export var keyValDiff:List<PipeFactory> = [
new KeyValueChangesFactory(),
new NullPipeFactory()
];
@ -26,7 +27,7 @@ export var keyValDiff = [
*
* @exportedAs angular2/pipes
*/
export var iterableDiff = [
export var iterableDiff:List<PipeFactory> = [
new IterableChangesFactory(),
new NullPipeFactory()
];
@ -36,12 +37,12 @@ export var iterableDiff = [
*
* @exportedAs angular2/pipes
*/
export var async = [
export var async:List<PipeFactory> = [
new AsyncPipeFactory(),
new NullPipeFactory()
];
export var defaultPipes = {
export var defaultPipes:Map<String, List<PipeFactory>> = {
"iterableDiff" : iterableDiff,
"keyValDiff" : keyValDiff,
"async" : async

View File

@ -1,6 +1,6 @@
import {Observable, ObservableWrapper} from 'angular2/src/facade/async';
import {isBlank, isPresent} from 'angular2/src/facade/lang';
import {Pipe, WrappedValue} from './pipe';
import {isBlank, isPresent, CONST} from 'angular2/src/facade/lang';
import {Pipe, WrappedValue, PipeFactory} from './pipe';
import {ChangeDetectorRef} from '../change_detector_ref';
/**
@ -52,7 +52,7 @@ export class AsyncPipe extends Pipe {
onDestroy():void {
if (isPresent(this._subscription)) {
this._dispose();
};
}
}
transform(obs:Observable):any {
@ -101,7 +101,12 @@ export class AsyncPipe extends Pipe {
*
* @exportedAs angular2/pipes
*/
export class AsyncPipeFactory {
export class AsyncPipeFactory extends PipeFactory {
@CONST()
constructor() {
super();
}
supports(obs):boolean {
return ObservableWrapper.isObservable(obs);
}

View File

@ -1,3 +1,4 @@
import {CONST} from 'angular2/src/facade/lang';
import {
isListLikeIterable,
iterateListLike,
@ -14,9 +15,14 @@ import {
looseIdentical,
} from 'angular2/src/facade/lang';
import {WrappedValue, Pipe} from './pipe';
import {WrappedValue, Pipe, PipeFactory} from './pipe';
export class IterableChangesFactory extends PipeFactory {
@CONST()
constructor() {
super();
}
export class IterableChangesFactory {
supports(obj):boolean {
return IterableChanges.supportsObj(obj);
}

View File

@ -1,12 +1,17 @@
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {stringify, looseIdentical, isJsObject} from 'angular2/src/facade/lang';
import {stringify, looseIdentical, isJsObject, CONST} from 'angular2/src/facade/lang';
import {WrappedValue, Pipe} from './pipe';
import {WrappedValue, Pipe, PipeFactory} from './pipe';
/**
* @exportedAs angular2/pipes
*/
export class KeyValueChangesFactory {
export class KeyValueChangesFactory extends PipeFactory {
@CONST()
constructor() {
super();
}
supports(obj):boolean {
return KeyValueChanges.supportsObj(obj);
}

View File

@ -1,10 +1,15 @@
import {isBlank} from 'angular2/src/facade/lang';
import {Pipe, WrappedValue} from './pipe';
import {isBlank, CONST} from 'angular2/src/facade/lang';
import {Pipe, WrappedValue, PipeFactory} from './pipe';
/**
* @exportedAs angular2/pipes
*/
export class NullPipeFactory {
export class NullPipeFactory extends PipeFactory {
@CONST()
constructor() {
super();
}
supports(obj):boolean {
return NullPipe.supportsObj(obj);
}

View File

@ -1,3 +1,5 @@
import {ABSTRACT, BaseException, CONST} from 'angular2/src/facade/lang';
/**
* Indicates that the result of a {@link Pipe} transformation has changed even though the reference has not changed.
*
@ -55,3 +57,22 @@ export class Pipe {
onDestroy() {}
transform(value:any):any {return null;}
}
@ABSTRACT()
export class PipeFactory {
@CONST()
constructor() {
}
supports(obs):boolean {
return _abstract();
}
create(cdRef):Pipe {
return _abstract();
}
}
function _abstract() {
return new BaseException('This method is abstract');
}