feat(pipes): add support for pure pipes

By default, pipes are pure. This means that an instance of a pipe will be reused and the pipe will be called only when its arguments change.

BREAKING CHANGE

Before:

@Pipe({name: 'date'}) class DatePipe {} defines an impure pipe.

After:

@Pipe({name: 'date'}) class DatePipe {} defines a pure pipe.
@Pipe({name: 'date', pure: false}) class DatePipe {} defines an impure pipe.

Closes #3966
This commit is contained in:
vsavkin
2015-09-08 09:17:58 -07:00
committed by Victor Savkin
parent 5a59e8be82
commit a8bdb693b9
16 changed files with 167 additions and 74 deletions

View File

@ -1,6 +1,6 @@
import {CONST, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
import {isPresent, CONST, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {InjectableMetadata} from 'angular2/src/core/di/metadata';
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
/**
* Directives allow you to attach behavior to elements in the DOM.
@ -861,11 +861,15 @@ export class ComponentMetadata extends DirectiveMetadata {
@CONST()
export class PipeMetadata extends InjectableMetadata {
name: string;
_pure: boolean;
constructor({name}: {name: string}) {
constructor({name, pure}: {name: string, pure: boolean}) {
super();
this.name = name;
this._pure = pure;
}
get pure(): boolean { return isPresent(this._pure) ? this._pure : true; }
}
/**