Skip to content

Commit 4dc6d74

Browse files
PatrickJStbosch
authored andcommitted
fix(lowercase,uppercase): make stateless pipes
same problem as `json` previously of transforming only on reference check Closes angular#3173 Closes angular#3189
1 parent 99587a9 commit 4dc6d74

File tree

3 files changed

+14
-40
lines changed

3 files changed

+14
-40
lines changed

modules/angular2/src/change_detection/change_detection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {IterableChangesFactory} from './pipes/iterable_changes';
77
import {KeyValueChangesFactory} from './pipes/keyvalue_changes';
88
import {ObservablePipeFactory} from './pipes/observable_pipe';
99
import {PromisePipeFactory} from './pipes/promise_pipe';
10-
import {UpperCaseFactory} from './pipes/uppercase_pipe';
11-
import {LowerCaseFactory} from './pipes/lowercase_pipe';
10+
import {UpperCasePipe} from './pipes/uppercase_pipe';
11+
import {LowerCasePipe} from './pipes/lowercase_pipe';
1212
import {JsonPipe} from './pipes/json_pipe';
1313
import {LimitToPipeFactory} from './pipes/limit_to_pipe';
1414
import {DatePipe} from './pipes/date_pipe';
@@ -81,13 +81,13 @@ export const async: List<PipeFactory> = CONST_EXPR([
8181
* Uppercase text transform.
8282
*/
8383
export const uppercase: List<PipeFactory> =
84-
CONST_EXPR([CONST_EXPR(new UpperCaseFactory()), CONST_EXPR(new NullPipeFactory())]);
84+
CONST_EXPR([CONST_EXPR(new UpperCasePipe()), CONST_EXPR(new NullPipeFactory())]);
8585

8686
/**
8787
* Lowercase text transform.
8888
*/
8989
export const lowercase: List<PipeFactory> =
90-
CONST_EXPR([CONST_EXPR(new LowerCaseFactory()), CONST_EXPR(new NullPipeFactory())]);
90+
CONST_EXPR([CONST_EXPR(new LowerCasePipe()), CONST_EXPR(new NullPipeFactory())]);
9191

9292
/**
9393
* Json stringify transform.
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
2-
import {Pipe, PipeFactory} from './pipe';
2+
import {Pipe, BasePipe, PipeFactory} from './pipe';
33
import {ChangeDetectorRef} from '../change_detector_ref';
44

55
/**
@@ -22,26 +22,13 @@ import {ChangeDetectorRef} from '../change_detector_ref';
2222
*
2323
* ```
2424
*/
25-
export class LowerCasePipe implements Pipe {
26-
_latestValue: string = null;
27-
25+
@CONST()
26+
export class LowerCasePipe extends BasePipe implements PipeFactory {
2827
supports(str: any): boolean { return isString(str); }
2928

30-
onDestroy(): void { this._latestValue = null; }
31-
3229
transform(value: string, args: List<any> = null): string {
33-
if (this._latestValue !== value) {
34-
this._latestValue = value;
35-
return StringWrapper.toLowerCase(value);
36-
} else {
37-
return this._latestValue;
38-
}
30+
return StringWrapper.toLowerCase(value);
3931
}
40-
}
41-
42-
@CONST()
43-
export class LowerCaseFactory implements PipeFactory {
44-
supports(str: any): boolean { return isString(str); }
4532

46-
create(cdRef: ChangeDetectorRef): Pipe { return new LowerCasePipe(); }
33+
create(cdRef: ChangeDetectorRef): Pipe { return this; }
4734
}
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
2-
import {Pipe, PipeFactory} from './pipe';
2+
import {Pipe, BasePipe, PipeFactory} from './pipe';
33
import {ChangeDetectorRef} from '../change_detector_ref';
44

55
/**
@@ -22,26 +22,13 @@ import {ChangeDetectorRef} from '../change_detector_ref';
2222
*
2323
* ```
2424
*/
25-
export class UpperCasePipe implements Pipe {
26-
_latestValue: string = null;
27-
25+
@CONST()
26+
export class UpperCasePipe extends BasePipe implements PipeFactory {
2827
supports(str: any): boolean { return isString(str); }
2928

30-
onDestroy(): void { this._latestValue = null; }
31-
3229
transform(value: string, args: List<any> = null): string {
33-
if (this._latestValue !== value) {
34-
this._latestValue = value;
35-
return StringWrapper.toUpperCase(value);
36-
} else {
37-
return this._latestValue;
38-
}
30+
return StringWrapper.toUpperCase(value);
3931
}
40-
}
41-
42-
@CONST()
43-
export class UpperCaseFactory implements PipeFactory {
44-
supports(str: any): boolean { return isString(str); }
4532

46-
create(cdRef: ChangeDetectorRef): Pipe { return new UpperCasePipe(); }
33+
create(cdRef: ChangeDetectorRef): Pipe { return this; }
4734
}

0 commit comments

Comments
 (0)