From 4afd2b413858e3295b2cbe2e933cbe58dd080d06 Mon Sep 17 00:00:00 2001 From: gdi2290 Date: Wed, 20 May 2015 14:00:39 -0700 Subject: [PATCH] feat(PromisePipe): remove ref onDestroy --- .../change_detection/pipes/promise_pipe.ts | 6 +++++- .../pipes/promise_pipe_spec.js | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/change_detection/pipes/promise_pipe.ts b/modules/angular2/src/change_detection/pipes/promise_pipe.ts index 159426386d..7fb0bbec25 100644 --- a/modules/angular2/src/change_detection/pipes/promise_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/promise_pipe.ts @@ -44,7 +44,11 @@ export class PromisePipe extends Pipe { supports(promise): boolean { return PromiseWrapper.isPromise(promise); } onDestroy(): void { - // NO-OP + if (isPresent(this._sourcePromise)) { + this._latestValue = null; + this._latestReturnedValue = null; + this._sourcePromise = null; + } } transform(promise: Promise): any { diff --git a/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js b/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js index 5119f19c5d..9099b0fea4 100644 --- a/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js +++ b/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js @@ -84,6 +84,26 @@ export function main() { async.done(); }, 0) })); + + describe("onDestroy", () => { + it("should do nothing when no source", () => { + expect(() => pipe.onDestroy()).not.toThrow(); + }); + + it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => { + pipe.transform(completer.promise); + expect(pipe.transform(completer.promise)).toBe(null); + completer.resolve(message) + + + TimerWrapper.setTimeout(() => { + expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); + pipe.onDestroy(); + expect(pipe.transform(completer.promise)).toBe(null); + async.done(); + }, 0); + })); + }); }); }); }