fix(lowercase,uppercase): make stateless pipes

same problem as `json` previously of transforming only on reference
check

Closes #3173
Closes #3189
This commit is contained in:
gdi2290 2015-07-22 02:19:16 -07:00 committed by Tobias Bosch
parent 99587a9907
commit 4dc6d748a9
3 changed files with 14 additions and 40 deletions

View File

@ -7,8 +7,8 @@ import {IterableChangesFactory} from './pipes/iterable_changes';
import {KeyValueChangesFactory} from './pipes/keyvalue_changes'; import {KeyValueChangesFactory} from './pipes/keyvalue_changes';
import {ObservablePipeFactory} from './pipes/observable_pipe'; import {ObservablePipeFactory} from './pipes/observable_pipe';
import {PromisePipeFactory} from './pipes/promise_pipe'; import {PromisePipeFactory} from './pipes/promise_pipe';
import {UpperCaseFactory} from './pipes/uppercase_pipe'; import {UpperCasePipe} from './pipes/uppercase_pipe';
import {LowerCaseFactory} from './pipes/lowercase_pipe'; import {LowerCasePipe} from './pipes/lowercase_pipe';
import {JsonPipe} from './pipes/json_pipe'; import {JsonPipe} from './pipes/json_pipe';
import {LimitToPipeFactory} from './pipes/limit_to_pipe'; import {LimitToPipeFactory} from './pipes/limit_to_pipe';
import {DatePipe} from './pipes/date_pipe'; import {DatePipe} from './pipes/date_pipe';
@ -81,13 +81,13 @@ export const async: List<PipeFactory> = CONST_EXPR([
* Uppercase text transform. * Uppercase text transform.
*/ */
export const uppercase: List<PipeFactory> = export const uppercase: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new UpperCaseFactory()), CONST_EXPR(new NullPipeFactory())]); CONST_EXPR([CONST_EXPR(new UpperCasePipe()), CONST_EXPR(new NullPipeFactory())]);
/** /**
* Lowercase text transform. * Lowercase text transform.
*/ */
export const lowercase: List<PipeFactory> = export const lowercase: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new LowerCaseFactory()), CONST_EXPR(new NullPipeFactory())]); CONST_EXPR([CONST_EXPR(new LowerCasePipe()), CONST_EXPR(new NullPipeFactory())]);
/** /**
* Json stringify transform. * Json stringify transform.

View File

@ -1,5 +1,5 @@
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang'; import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
import {Pipe, PipeFactory} from './pipe'; import {Pipe, BasePipe, PipeFactory} from './pipe';
import {ChangeDetectorRef} from '../change_detector_ref'; import {ChangeDetectorRef} from '../change_detector_ref';
/** /**
@ -22,26 +22,13 @@ import {ChangeDetectorRef} from '../change_detector_ref';
* *
* ``` * ```
*/ */
export class LowerCasePipe implements Pipe { @CONST()
_latestValue: string = null; export class LowerCasePipe extends BasePipe implements PipeFactory {
supports(str: any): boolean { return isString(str); } supports(str: any): boolean { return isString(str); }
onDestroy(): void { this._latestValue = null; }
transform(value: string, args: List<any> = null): string { transform(value: string, args: List<any> = null): string {
if (this._latestValue !== value) { return StringWrapper.toLowerCase(value);
this._latestValue = value;
return StringWrapper.toLowerCase(value);
} else {
return this._latestValue;
}
} }
}
@CONST() create(cdRef: ChangeDetectorRef): Pipe { return this; }
export class LowerCaseFactory implements PipeFactory {
supports(str: any): boolean { return isString(str); }
create(cdRef: ChangeDetectorRef): Pipe { return new LowerCasePipe(); }
} }

View File

@ -1,5 +1,5 @@
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang'; import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
import {Pipe, PipeFactory} from './pipe'; import {Pipe, BasePipe, PipeFactory} from './pipe';
import {ChangeDetectorRef} from '../change_detector_ref'; import {ChangeDetectorRef} from '../change_detector_ref';
/** /**
@ -22,26 +22,13 @@ import {ChangeDetectorRef} from '../change_detector_ref';
* *
* ``` * ```
*/ */
export class UpperCasePipe implements Pipe { @CONST()
_latestValue: string = null; export class UpperCasePipe extends BasePipe implements PipeFactory {
supports(str: any): boolean { return isString(str); } supports(str: any): boolean { return isString(str); }
onDestroy(): void { this._latestValue = null; }
transform(value: string, args: List<any> = null): string { transform(value: string, args: List<any> = null): string {
if (this._latestValue !== value) { return StringWrapper.toUpperCase(value);
this._latestValue = value;
return StringWrapper.toUpperCase(value);
} else {
return this._latestValue;
}
} }
}
@CONST() create(cdRef: ChangeDetectorRef): Pipe { return this; }
export class UpperCaseFactory implements PipeFactory {
supports(str: any): boolean { return isString(str); }
create(cdRef: ChangeDetectorRef): Pipe { return new UpperCasePipe(); }
} }