fix(JsonPipe): always transform to json

BREAKING CHANGE:

no longer cache ref
This commit is contained in:
gdi2290
2015-06-05 10:44:01 -07:00
committed by vsavkin
parent b6e95bb96e
commit e77710a372
3 changed files with 24 additions and 46 deletions

View File

@ -1,5 +1,5 @@
import {DynamicProtoChangeDetector, JitProtoChangeDetector} from './proto_change_detector';
import {PipeFactory} from './pipes/pipe';
import {PipeFactory, Pipe} from './pipes/pipe';
import {PipeRegistry} from './pipes/pipe_registry';
import {IterableChangesFactory} from './pipes/iterable_changes';
import {KeyValueChangesFactory} from './pipes/keyvalue_changes';
@ -7,7 +7,7 @@ import {ObservablePipeFactory} from './pipes/observable_pipe';
import {PromisePipeFactory} from './pipes/promise_pipe';
import {UpperCaseFactory} from './pipes/uppercase_pipe';
import {LowerCaseFactory} from './pipes/lowercase_pipe';
import {JsonPipeFactory} from './pipes/json_pipe';
import {JsonPipe} from './pipes/json_pipe';
import {NullPipeFactory} from './pipes/null_pipe';
import {ChangeDetection, ProtoChangeDetector, ChangeDetectorDefinition} from './interfaces';
import {Injectable} from 'angular2/src/di/decorators';
@ -55,7 +55,7 @@ export var lowercase: List<PipeFactory> = [new LowerCaseFactory(), new NullPipeF
*
* @exportedAs angular2/pipes
*/
export var json: List<PipeFactory> = [new JsonPipeFactory(), new NullPipeFactory()];
export var json: List<PipeFactory | Pipe> = [new JsonPipe(), new NullPipeFactory()];
export var defaultPipes = {
"iterableDiff": iterableDiff,

View File

@ -1,4 +1,4 @@
import {isBlank, isPresent, CONST, Json} from 'angular2/src/facade/lang';
import {isBlank, isPresent, Json} from 'angular2/src/facade/lang';
import {Pipe, PipeFactory} from './pipe';
/**
@ -27,48 +27,9 @@ import {Pipe, PipeFactory} from './pipe';
* @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);
}
}
transform(value): string { return Json.stringify(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(); }
create(cdRef): Pipe { return this }
}