Tobias Bosch 8aa3fcfb63 chore(build): don’t include export var __esModule = true in every file
But do it during the build process for cjs.
Right now we only need this when we transpile from ts
directly to es5. This is only the case in our
cis build, as for our browser build we only transpile
from ts to es6 via ts and then use traceur to do
the rest.
2015-05-19 15:12:59 -07:00

75 lines
1.4 KiB
TypeScript

import {isBlank, isPresent, CONST, Json} from 'angular2/src/facade/lang';
import {Pipe, PipeFactory} from './pipe';
/**
* Implements json transforms to any object.
*
* # Example
*
* In this example we transform the user object to json.
*
* ```
* @Component({
* selector: "user-cmp"
* })
* @View({
* template: "User: {{ user | json }}"
* })
* class Username {
* user:Object
* constructor() {
* this.user = { name: "PatrickJS" };
* }
* }
*
* ```
*
* @exportedAs angular2/pipes
*/
export class JsonPipe extends Pipe {
_latestRef: any;
_latestValue: any;
constructor() {
super();
this._latestRef = null;
this._latestValue = null;
}
onDestroy(): void {
if (isPresent(this._latestValue)) {
this._latestRef = null;
this._latestValue = null;
}
}
supports(obj): boolean { return true; }
transform(value): any {
if (value === this._latestRef) {
return this._latestValue;
} else {
return this._prettyPrint(value);
}
}
_prettyPrint(value) {
this._latestRef = value;
this._latestValue = Json.stringify(value);
return this._latestValue;
}
}
/**
* Provides a factory for [JsonPipeFactory].
*
* @exportedAs angular2/pipes
*/
@CONST()
export class JsonPipeFactory extends PipeFactory {
constructor() { super(); }
supports(obj): boolean { return true; }
create(cdRef): Pipe { return new JsonPipe(); }
}