refactor(Pipes): integrate review feedback

Closes #4947
This commit is contained in:
Victor Berchet 2015-10-27 16:37:08 -07:00
parent e7f9924b18
commit 7677dc976e
4 changed files with 13 additions and 9 deletions

View File

@ -948,7 +948,7 @@ export class ComponentMetadata extends DirectiveMetadata {
/**
* Declare reusable pipe function.
*
* A "pure" pipe is only re-evaluated when any of its input or arguments changes.
* A "pure" pipe is only re-evaluated when either the input or any of the arguments change.
*
* When not specified, pipes default to being pure.
*

View File

@ -21,12 +21,17 @@ import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
var defaultLocale: string = 'en-US';
/**
* WARNING: this pipe uses the Internationalization API.
* Therefore it is only reliable in Chrome and Opera browsers.
*
* Formats a date value to a string based on the requested format.
*
*##Usage
* WARNINGS:
* - this pipe is marked as pure hence it will not be re-evaluated when the input is mutated.
* Instead users should treat the date as an immutable object and change the reference when the
* pipe needs to re-run (this is to avoid reformatting the date on every change detection run
* which would be an expensive operation).
* - this pipe uses the Internationalization API. Therefore it is only reliable in Chrome and Opera
* browsers.
*
* ## Usage
*
* expression | date[:format]
*
@ -78,7 +83,7 @@ var defaultLocale: string = 'en-US';
* {{ dateObj | date:'mmss' }} // output is '43:11'
*/
@CONST()
@Pipe({name: 'date', pure: false})
@Pipe({name: 'date', pure: true})
@Injectable()
export class DatePipe implements PipeTransform {
/** @internal */

View File

@ -5,7 +5,6 @@ import {Pipe} from 'angular2/src/core/metadata';
/**
* Implements json transforms to any object.
* The json pipe runs all the time checking for changes on the transformed object.
*
* ### Example
*

View File

@ -24,8 +24,8 @@ export function main() {
pipe = new DatePipe();
});
it('should be marked as non-pure',
() => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(false); });
it('should be marked as pure',
() => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(true); });
describe("supports", () => {
it("should support date", () => { expect(pipe.supports(date)).toBe(true); });