fix: export top-level pipe factories as const

Also appComponent(Ref|Type)Token

Related to https://github.com/angular/angular/issues/1485
This commit is contained in:
Kevin Moore 2015-06-22 17:11:55 -07:00
parent 7a7b3a6cb9
commit 393f703a97
9 changed files with 35 additions and 17 deletions

View File

@ -14,59 +14,67 @@ import {NullPipeFactory} from './pipes/null_pipe';
import {ChangeDetection, ProtoChangeDetector, ChangeDetectorDefinition} from './interfaces';
import {Inject, Injectable, OpaqueToken, Optional} from 'angular2/di';
import {List, StringMap, StringMapWrapper} from 'angular2/src/facade/collection';
import {CONST_EXPR, isPresent, BaseException} from 'angular2/src/facade/lang';
import {CONST, CONST_EXPR, isPresent, BaseException} from 'angular2/src/facade/lang';
/**
* Structural diffing for `Object`s and `Map`s.
*
* @exportedAs angular2/pipes
*/
export var keyValDiff: List<PipeFactory> = [new KeyValueChangesFactory(), new NullPipeFactory()];
export const keyValDiff: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new KeyValueChangesFactory()), CONST_EXPR(new NullPipeFactory())]);
/**
* Structural diffing for `Iterable` types such as `Array`s.
*
* @exportedAs angular2/pipes
*/
export var iterableDiff: List<PipeFactory> = [new IterableChangesFactory(), new NullPipeFactory()];
export const iterableDiff: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new IterableChangesFactory()), CONST_EXPR(new NullPipeFactory())]);
/**
* Async binding to such types as Observable.
*
* @exportedAs angular2/pipes
*/
export var async: List<PipeFactory> =
[new ObservablePipeFactory(), new PromisePipeFactory(), new NullPipeFactory()];
export const async: List<PipeFactory> = CONST_EXPR([
CONST_EXPR(new ObservablePipeFactory()),
CONST_EXPR(new PromisePipeFactory()),
CONST_EXPR(new NullPipeFactory())
]);
/**
* Uppercase text transform.
*
* @exportedAs angular2/pipes
*/
export var uppercase: List<PipeFactory> = [new UpperCaseFactory(), new NullPipeFactory()];
export const uppercase: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new UpperCaseFactory()), CONST_EXPR(new NullPipeFactory())]);
/**
* Lowercase text transform.
*
* @exportedAs angular2/pipes
*/
export var lowercase: List<PipeFactory> = [new LowerCaseFactory(), new NullPipeFactory()];
export const lowercase: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new LowerCaseFactory()), CONST_EXPR(new NullPipeFactory())]);
/**
* Json stringify transform.
*
* @exportedAs angular2/pipes
*/
export var json: List<PipeFactory | Pipe> = [new JsonPipe(), new NullPipeFactory()];
export const json: List<PipeFactory | Pipe> =
CONST_EXPR([CONST_EXPR(new JsonPipe()), CONST_EXPR(new NullPipeFactory())]);
export var defaultPipes = {
export const defaultPipes = CONST_EXPR({
"iterableDiff": iterableDiff,
"keyValDiff": keyValDiff,
"async": async,
"uppercase": uppercase,
"lowercase": lowercase,
"json": json
};
});
/**
* Map from {@link ChangeDetectorDefinition#id} to a factory method which takes a
@ -137,6 +145,7 @@ export class DynamicChangeDetection extends ChangeDetection {
* @exportedAs angular2/change_detection
*/
@Injectable()
@CONST()
export class JitChangeDetection extends ChangeDetection {
constructor(public registry: PipeRegistry) { super(); }
@ -147,4 +156,4 @@ export class JitChangeDetection extends ChangeDetection {
}
}
export var defaultPipeRegistry: PipeRegistry = new PipeRegistry(defaultPipes);
export const defaultPipeRegistry: PipeRegistry = CONST_EXPR(new PipeRegistry(defaultPipes));

View File

@ -1,4 +1,5 @@
import {List} from 'angular2/src/facade/collection';
import {CONST} from 'angular2/src/facade/lang';
import {Locals} from './parser/locals';
import {BindingRecord} from './binding_record';
import {DirectiveRecord} from './directive_record';
@ -29,6 +30,7 @@ import {DirectiveRecord} from './directive_record';
* ```
* @exportedAs angular2/change_detection
*/
@CONST()
export class ChangeDetection {
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
return null;

View File

@ -1,4 +1,4 @@
import {isBlank, isPresent, Json} from 'angular2/src/facade/lang';
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
import {Pipe, BasePipe, PipeFactory} from './pipe';
/**
@ -26,6 +26,7 @@ import {Pipe, BasePipe, PipeFactory} from './pipe';
*
* @exportedAs angular2/pipes
*/
@CONST()
export class JsonPipe extends BasePipe {
transform(value): string { return Json.stringify(value); }

View File

@ -1,4 +1,4 @@
import {isString, StringWrapper} from 'angular2/src/facade/lang';
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
import {Pipe} from './pipe';
/**
@ -43,6 +43,7 @@ export class LowerCasePipe implements Pipe {
/**
* @exportedAs angular2/pipes
*/
@CONST()
export class LowerCaseFactory {
supports(str): boolean { return isString(str); }

View File

@ -70,6 +70,7 @@ export interface Pipe {
* }
* ```
*/
@CONST()
export class BasePipe implements Pipe {
supports(obj): boolean { return true; }
onDestroy(): void {}

View File

@ -5,6 +5,7 @@ import {Injectable} from 'angular2/src/di/decorators';
import {ChangeDetectorRef} from '../change_detector_ref';
@Injectable()
@CONST()
export class PipeRegistry {
constructor(public config) {}

View File

@ -1,5 +1,5 @@
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {isBlank, isPresent, isPromise} from 'angular2/src/facade/lang';
import {isBlank, isPresent, isPromise, CONST} from 'angular2/src/facade/lang';
import {Pipe, WrappedValue} from './pipe';
import {ChangeDetectorRef} from '../change_detector_ref';
@ -80,6 +80,7 @@ export class PromisePipe implements Pipe {
*
* @exportedAs angular2/pipes
*/
@CONST()
export class PromisePipeFactory {
supports(promise): boolean { return isPromise(promise); }

View File

@ -1,4 +1,4 @@
import {isString, StringWrapper} from 'angular2/src/facade/lang';
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
import {Pipe} from './pipe';
/**
@ -43,6 +43,7 @@ export class UpperCasePipe implements Pipe {
/**
* @exportedAs angular2/pipes
*/
@CONST()
export class UpperCaseFactory {
supports(str): boolean { return isString(str); }

View File

@ -1,4 +1,5 @@
import {OpaqueToken} from 'angular2/di';
import {CONST_EXPR} from 'angular2/src/facade/lang';
export var appComponentRefToken: OpaqueToken = new OpaqueToken('ComponentRef');
export var appComponentTypeToken: OpaqueToken = new OpaqueToken('RootComponent');
export const appComponentRefToken: OpaqueToken = CONST_EXPR(new OpaqueToken('ComponentRef'));
export const appComponentTypeToken: OpaqueToken = CONST_EXPR(new OpaqueToken('RootComponent'));