Skip to content

Commit

Permalink
fix: export top-level pipe factories as const
Browse files Browse the repository at this point in the history
Also appComponent(Ref|Type)Token

Related to #1485
  • Loading branch information
kevmoo committed Jun 25, 2015
1 parent 7a7b3a6 commit 393f703
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
31 changes: 20 additions & 11 deletions modules/angular2/src/change_detection/change_detection.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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(); }

Expand All @@ -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));
2 changes: 2 additions & 0 deletions modules/angular2/src/change_detection/interfaces.ts
@@ -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';
Expand Down Expand Up @@ -29,6 +30,7 @@ import {DirectiveRecord} from './directive_record';
* ```
* @exportedAs angular2/change_detection
*/
@CONST()
export class ChangeDetection {
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
return null;
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/change_detection/pipes/json_pipe.ts
@@ -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';

/**
Expand Down Expand Up @@ -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); }

Expand Down
@@ -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';

/**
Expand Down Expand Up @@ -43,6 +43,7 @@ export class LowerCasePipe implements Pipe {
/**
* @exportedAs angular2/pipes
*/
@CONST()
export class LowerCaseFactory {
supports(str): boolean { return isString(str); }

Expand Down
1 change: 1 addition & 0 deletions modules/angular2/src/change_detection/pipes/pipe.ts
Expand Up @@ -70,6 +70,7 @@ export interface Pipe {
* }
* ```
*/
@CONST()
export class BasePipe implements Pipe {
supports(obj): boolean { return true; }
onDestroy(): void {}
Expand Down
Expand Up @@ -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) {}

Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/change_detection/pipes/promise_pipe.ts
@@ -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';

Expand Down Expand Up @@ -80,6 +80,7 @@ export class PromisePipe implements Pipe {
*
* @exportedAs angular2/pipes
*/
@CONST()
export class PromisePipeFactory {
supports(promise): boolean { return isPromise(promise); }

Expand Down
@@ -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';

/**
Expand Down Expand Up @@ -43,6 +43,7 @@ export class UpperCasePipe implements Pipe {
/**
* @exportedAs angular2/pipes
*/
@CONST()
export class UpperCaseFactory {
supports(str): boolean { return isString(str); }

Expand Down
5 changes: 3 additions & 2 deletions modules/angular2/src/core/application_tokens.ts
@@ -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'));

0 comments on commit 393f703

Please sign in to comment.