@@ -18,7 +18,7 @@ class WindowToggleOperator<T, R, O> implements Operator<T, R> {
18
18
private closingSelector : ( openValue : O ) => Observable < any > ) {
19
19
}
20
20
21
- call ( subscriber : Subscriber < T > ) : Subscriber < T > {
21
+ call ( subscriber : Subscriber < Observable < T > > ) : Subscriber < T > {
22
22
return new WindowToggleSubscriber < T , O > (
23
23
subscriber , this . openings , this . closingSelector
24
24
) ;
@@ -33,7 +33,7 @@ interface WindowContext<T> {
33
33
class WindowToggleSubscriber < T , O > extends Subscriber < T > {
34
34
private contexts : Array < WindowContext < T > > = [ ] ;
35
35
36
- constructor ( destination : Subscriber < T > ,
36
+ constructor ( protected destination : Subscriber < Observable < T > > ,
37
37
private openings : Observable < O > ,
38
38
private closingSelector : ( openValue : O ) => Observable < any > ) {
39
39
super ( destination ) ;
@@ -72,24 +72,29 @@ class WindowToggleSubscriber<T, O> extends Subscriber<T> {
72
72
if ( closingNotifier === errorObject ) {
73
73
this . error ( closingNotifier . e ) ;
74
74
} else {
75
- let context = {
76
- window : new Subject < T > ( ) ,
77
- subscription : new Subscription ( )
78
- } ;
75
+ const destination = this . destination ;
76
+ const window = new Subject < T > ( ) ;
77
+ const subscription = new Subscription ( ) ;
78
+ const context = { window , subscription } ;
79
79
this . contexts . push ( context ) ;
80
- this . destination . next ( context . window ) ;
81
80
const subscriber = new WindowClosingNotifierSubscriber < T , O > ( this , context ) ;
82
- const subscription = closingNotifier . _subscribe ( subscriber ) ;
83
- this . add ( context . subscription . add ( subscription ) ) ;
81
+ const closingSubscription = closingNotifier . _subscribe ( subscriber ) ;
82
+ subscription . add ( closingSubscription ) ;
83
+ destination . add ( subscription ) ;
84
+ destination . add ( window ) ;
85
+ destination . next ( window ) ;
84
86
}
85
87
}
86
88
87
89
closeWindow ( context : WindowContext < T > ) {
88
90
const { window, subscription } = context ;
89
91
const contexts = this . contexts ;
92
+ const destination = this . destination ;
93
+
90
94
contexts . splice ( contexts . indexOf ( context ) , 1 ) ;
91
95
window . complete ( ) ;
92
- this . remove ( subscription ) ;
96
+ destination . remove ( subscription ) ;
97
+ destination . remove ( window ) ;
93
98
subscription . unsubscribe ( ) ;
94
99
}
95
100
}
0 commit comments