File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export class Observable<T> implements IObservable<T> {
29
29
30
30
safelyExecuteFunc ( observer : IObserver < T > , cSub : CompositeSubscription ) {
31
31
const r = SafeExecutor ( ( ) => {
32
- cSub . add ( Subscription . from ( this . func ( SubscriptionObserver . of ( observer ) ) ) )
32
+ cSub . add ( Subscription . from ( this . func ( SubscriptionObserver . from ( observer ) ) ) )
33
33
} )
34
34
if ( r . type === Safety . error && observer . error ) {
35
35
observer . error ( r . value as Error )
Original file line number Diff line number Diff line change 5
5
import { ISubscriptionObserver } from './types/core/ISubscriptionObserver' ;
6
6
import { IObserver } from './types/core/IObserver' ;
7
7
8
+ export class SubscriptionObserverStub < T > implements ISubscriptionObserver < T > {
9
+ closed : boolean ;
10
+
11
+ next ( val : T ) : void {
12
+ }
13
+
14
+ error ( err : Error ) : void {
15
+ }
16
+
17
+ complete ( ) : void {
18
+ }
19
+ }
20
+
8
21
export class SubscriptionObserver < T > implements ISubscriptionObserver < T > {
9
22
closed : boolean ;
10
23
11
24
constructor ( private sink : IObserver < T > ) {
12
- this . closed = ! this . sink . next
25
+ this . closed = false
13
26
}
14
27
15
28
next ( val : T ) : void {
@@ -18,15 +31,16 @@ export class SubscriptionObserver<T> implements ISubscriptionObserver<T> {
18
31
19
32
error ( err : Error ) : void {
20
33
this . sink . error ( err )
21
-
22
34
}
23
35
24
36
complete ( ) : void {
25
- if ( this . sink . complete ) this . sink . complete ( )
37
+ this . sink . complete ( )
26
38
this . closed = true
27
39
}
28
40
29
- static of < T > ( observer : IObserver < T > ) {
41
+ static from < T > ( observer : IObserver < T > ) {
42
+ if ( ! observer . next || ! observer . complete || ! observer . error )
43
+ return new SubscriptionObserverStub ( )
30
44
return new SubscriptionObserver ( observer )
31
45
}
32
46
}
You can’t perform that action at this time.
0 commit comments