Skip to content

Commit 4afd2b4

Browse files
committed
feat(PromisePipe): remove ref onDestroy
1 parent dee4ecb commit 4afd2b4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

modules/angular2/src/change_detection/pipes/promise_pipe.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export class PromisePipe extends Pipe {
4444
supports(promise): boolean { return PromiseWrapper.isPromise(promise); }
4545

4646
onDestroy(): void {
47-
// NO-OP
47+
if (isPresent(this._sourcePromise)) {
48+
this._latestValue = null;
49+
this._latestReturnedValue = null;
50+
this._sourcePromise = null;
51+
}
4852
}
4953

5054
transform(promise: Promise<any>): any {

modules/angular2/test/change_detection/pipes/promise_pipe_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ export function main() {
8484
async.done();
8585
}, 0)
8686
}));
87+
88+
describe("onDestroy", () => {
89+
it("should do nothing when no source", () => {
90+
expect(() => pipe.onDestroy()).not.toThrow();
91+
});
92+
93+
it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => {
94+
pipe.transform(completer.promise);
95+
expect(pipe.transform(completer.promise)).toBe(null);
96+
completer.resolve(message)
97+
98+
99+
TimerWrapper.setTimeout(() => {
100+
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
101+
pipe.onDestroy();
102+
expect(pipe.transform(completer.promise)).toBe(null);
103+
async.done();
104+
}, 0);
105+
}));
106+
});
87107
});
88108
});
89109
}

0 commit comments

Comments
 (0)