@@ -8,9 +8,9 @@ import {rxSubscriber} from './symbol/rxSubscriber';
8
8
9
9
export class Subject < T > extends Observable < T > implements Observer < T > , Subscription {
10
10
11
- static create < T > ( source : Observable < T > , destination : Observer < T > ) : Subject < T > {
11
+ static create : Function = < T > ( source : Observable < T > , destination : Observer < T > ) : Subject < T > = > {
12
12
return new Subject < T > ( source , destination ) ;
13
- }
13
+ } ;
14
14
15
15
constructor ( source ?: Observable < T > , destination ?: Observer < T > ) {
16
16
super ( ) ;
@@ -127,60 +127,72 @@ export class Subject<T> extends Observable<T> implements Observer<T>, Subscripti
127
127
if ( this . destination ) {
128
128
this . destination . next ( value ) ;
129
129
} else {
130
- let index = - 1 ;
131
- const observers = this . observers . slice ( 0 ) ;
132
- const len = observers . length ;
130
+ this . _finalNext ( value ) ;
131
+ }
132
+ }
133
133
134
- while ( ++ index < len ) {
135
- observers [ index ] . next ( value ) ;
136
- }
134
+ protected _finalNext ( value : T ) : void {
135
+ let index = - 1 ;
136
+ const observers = this . observers . slice ( 0 ) ;
137
+ const len = observers . length ;
138
+
139
+ while ( ++ index < len ) {
140
+ observers [ index ] . next ( value ) ;
137
141
}
138
142
}
139
143
140
144
protected _error ( err : any ) : void {
141
145
if ( this . destination ) {
142
146
this . destination . error ( err ) ;
143
147
} else {
144
- let index = - 1 ;
145
- const observers = this . observers ;
146
- const len = observers . length ;
148
+ this . _finalError ( err ) ;
149
+ }
150
+ }
147
151
148
- // optimization to block our SubjectSubscriptions from
149
- // splicing themselves out of the observers list one by one.
150
- this . observers = null ;
151
- this . isUnsubscribed = true ;
152
+ protected _finalError ( err : any ) : void {
153
+ let index = - 1 ;
154
+ const observers = this . observers ;
155
+ const len = observers . length ;
152
156
153
- while ( ++ index < len ) {
154
- observers [ index ] . error ( err ) ;
155
- }
156
-
157
- this . isUnsubscribed = false ;
157
+ // optimization to block our SubjectSubscriptions from
158
+ // splicing themselves out of the observers list one by one.
159
+ this . observers = null ;
160
+ this . isUnsubscribed = true ;
158
161
159
- this . unsubscribe ( ) ;
162
+ while ( ++ index < len ) {
163
+ observers [ index ] . error ( err ) ;
160
164
}
165
+
166
+ this . isUnsubscribed = false ;
167
+
168
+ this . unsubscribe ( ) ;
161
169
}
162
170
163
171
protected _complete ( ) : void {
164
172
if ( this . destination ) {
165
173
this . destination . complete ( ) ;
166
174
} else {
167
- let index = - 1 ;
168
- const observers = this . observers ;
169
- const len = observers . length ;
175
+ this . _finalComplete ( ) ;
176
+ }
177
+ }
170
178
171
- // optimization to block our SubjectSubscriptions from
172
- // splicing themselves out of the observers list one by one.
173
- this . observers = null ;
174
- this . isUnsubscribed = true ;
179
+ protected _finalComplete ( ) : void {
180
+ let index = - 1 ;
181
+ const observers = this . observers ;
182
+ const len = observers . length ;
175
183
176
- while ( ++ index < len ) {
177
- observers [ index ] . complete ( ) ;
178
- }
179
-
180
- this . isUnsubscribed = false ;
184
+ // optimization to block our SubjectSubscriptions from
185
+ // splicing themselves out of the observers list one by one.
186
+ this . observers = null ;
187
+ this . isUnsubscribed = true ;
181
188
182
- this . unsubscribe ( ) ;
189
+ while ( ++ index < len ) {
190
+ observers [ index ] . complete ( ) ;
183
191
}
192
+
193
+ this . isUnsubscribed = false ;
194
+
195
+ this . unsubscribe ( ) ;
184
196
}
185
197
186
198
[ rxSubscriber ] ( ) {
0 commit comments