Skip to content

Commit c086a0e

Browse files
committed
return subscription stubs if props not defined
1 parent 7088446 commit c086a0e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Observable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Observable<T> implements IObservable<T> {
2929

3030
safelyExecuteFunc (observer: IObserver<T>, cSub: CompositeSubscription) {
3131
const r = SafeExecutor(() => {
32-
cSub.add(Subscription.from(this.func(SubscriptionObserver.of(observer))))
32+
cSub.add(Subscription.from(this.func(SubscriptionObserver.from(observer))))
3333
})
3434
if (r.type === Safety.error && observer.error) {
3535
observer.error(r.value as Error)

src/SubscriptionObserver.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,24 @@
55
import {ISubscriptionObserver} from './types/core/ISubscriptionObserver';
66
import {IObserver} from './types/core/IObserver';
77

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+
821
export class SubscriptionObserver<T> implements ISubscriptionObserver<T> {
922
closed: boolean;
1023

1124
constructor (private sink: IObserver<T>) {
12-
this.closed = !this.sink.next
25+
this.closed = false
1326
}
1427

1528
next (val: T): void {
@@ -18,15 +31,16 @@ export class SubscriptionObserver<T> implements ISubscriptionObserver<T> {
1831

1932
error (err: Error): void {
2033
this.sink.error(err)
21-
2234
}
2335

2436
complete (): void {
25-
if (this.sink.complete) this.sink.complete()
37+
this.sink.complete()
2638
this.closed = true
2739
}
2840

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()
3044
return new SubscriptionObserver(observer)
3145
}
3246
}

0 commit comments

Comments
 (0)