File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
src/change_detection/pipes
test/change_detection/pipes Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments