feat(PromisePipe): remove ref onDestroy

This commit is contained in:
gdi2290 2015-05-20 14:00:39 -07:00
parent dee4ecbb3f
commit 4afd2b4138
2 changed files with 25 additions and 1 deletions

View File

@ -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>): any {

View File

@ -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);
}));
});
});
});
}