Skip to content

Commit

Permalink
perf(switch): make switch observer only once
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Feb 4, 2017
1 parent 1de57b6 commit 6cfb25b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/operators/Switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class SwitchValueObserver<T> implements Observer<T> {

class SwitchObserver<T> implements Observer<Observable<T>> {
private currentSub: LinkedListNode<Subscription> | undefined = void 0
private sink: SwitchValueObserver<T>

constructor (private sink: Observer<T>,
constructor (private mainSink: Observer<T>,
private cSub: CompositeSubscription,
private scheduler: Scheduler) {
this.sink = new SwitchValueObserver(mainSink)
}

private removeCurrentSub () {
Expand All @@ -43,7 +45,7 @@ class SwitchObserver<T> implements Observer<Observable<T>> {
}

next (val: Observable<T>): void {
this.setCurrentSub(val.subscribe(new SwitchValueObserver(this.sink), this.scheduler))
this.setCurrentSub(val.subscribe(this.sink, this.scheduler))
}

error (err: Error): void {
Expand All @@ -52,7 +54,7 @@ class SwitchObserver<T> implements Observer<Observable<T>> {

complete (): void {
this.removeCurrentSub()
this.sink.complete()
this.mainSink.complete()
}
}

Expand Down

0 comments on commit 6cfb25b

Please sign in to comment.