diff --git a/modules/angular2/src/core/metadata/directives.ts b/modules/angular2/src/core/metadata/directives.ts index 8bddbd06d5..0f7763a904 100644 --- a/modules/angular2/src/core/metadata/directives.ts +++ b/modules/angular2/src/core/metadata/directives.ts @@ -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. * diff --git a/modules/angular2/src/core/pipes/date_pipe.ts b/modules/angular2/src/core/pipes/date_pipe.ts index b1c39d5e6e..aabf0988db 100644 --- a/modules/angular2/src/core/pipes/date_pipe.ts +++ b/modules/angular2/src/core/pipes/date_pipe.ts @@ -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 */ diff --git a/modules/angular2/src/core/pipes/json_pipe.ts b/modules/angular2/src/core/pipes/json_pipe.ts index 8eaaa401a6..b752ab7329 100644 --- a/modules/angular2/src/core/pipes/json_pipe.ts +++ b/modules/angular2/src/core/pipes/json_pipe.ts @@ -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 * diff --git a/modules/angular2/test/core/pipes/date_pipe_spec.ts b/modules/angular2/test/core/pipes/date_pipe_spec.ts index 31ca411f03..7e2ca2e5d5 100644 --- a/modules/angular2/test/core/pipes/date_pipe_spec.ts +++ b/modules/angular2/test/core/pipes/date_pipe_spec.ts @@ -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); });