Skip to content

Commit

Permalink
refactor(merge/flatMap/expand): remove use of innerSubscription and u…
Browse files Browse the repository at this point in the history
…se subscriber instead
  • Loading branch information
benlesh committed Sep 15, 2015
1 parent 82deffb commit d65e7ea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
8 changes: 3 additions & 5 deletions src/operators/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ class ExpandSubscriber<T, R> extends Subscriber<T> {
if(result._isScalar) {
this._next(result.value);
} else {
let innerSub = new Subscription();
this.active++;
innerSub.add(result.subscribe(new ExpandInnerSubscriber(this.destination, this, innerSub)));
this.add(innerSub);
this.add(result.subscribe(new ExpandInnerSubscriber(this.destination, this)));
}
}
} else {
Expand Down Expand Up @@ -83,7 +81,7 @@ class ExpandSubscriber<T, R> extends Subscriber<T> {
}

class ExpandInnerSubscriber<T, R> extends Subscriber<T> {
constructor(destination: Observer<T>, private parent: ExpandSubscriber<T, R>, private innerSub: Subscription<T>) {
constructor(destination: Observer<T>, private parent: ExpandSubscriber<T, R>) {
super(destination);
}

Expand All @@ -92,6 +90,6 @@ class ExpandInnerSubscriber<T, R> extends Subscriber<T> {
}

_complete() {
this.parent.notifyComplete(this.innerSub);
this.parent.notifyComplete(this);
}
}
7 changes: 2 additions & 5 deletions src/operators/flatMap-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ export class FlatMapSubscriber<T, R, R2> extends Subscriber<T> {
this.destination.next(observable.value);
}
} else {
const innerSub = new Subscription();
this.add(innerSub);
this.active++;
innerSub.add(observable.subscribe(new FlatMapInnerSubscriber(this.destination, this, innerSub, value, index, resultSelector)));
this.add(observable.subscribe(new FlatMapInnerSubscriber(this.destination, this, value, index, resultSelector)));
}
}

Expand All @@ -95,7 +93,6 @@ export class FlatMapInnerSubscriber<T, R, R2> extends Subscriber<R> {
index: number = 0;

constructor(destination: Observer<R>, private parent: FlatMapSubscriber<any, R, R2>,
private innerSub: Subscription<R>,
private outerValue: T,
private outerIndex: number,
private resultSelector?: (innerValue: T, outerValue: R, innerIndex: number, outerIndex: number) => R2) {
Expand All @@ -118,6 +115,6 @@ export class FlatMapInnerSubscriber<T, R, R2> extends Subscriber<R> {
}

_complete() {
this.parent.notifyComplete(this.innerSub);
this.parent.notifyComplete(this);
}
}
9 changes: 3 additions & 6 deletions src/operators/mergeAll-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ export class MergeAllSubscriber<T> extends Subscriber<T> {
if(observable._isScalar) {
this.destination.next(observable.value);
} else {
const innerSub = new Subscription();
this.add(innerSub);
this.active++;
innerSub.add(observable.subscribe(new MergeAllInnerSubscriber(this.destination, this, innerSub)));
this.add(observable.subscribe(new MergeAllInnerSubscriber(this.destination, this)))
}
} else {
this.buffer.push(observable);
Expand All @@ -57,12 +55,11 @@ export class MergeAllSubscriber<T> extends Subscriber<T> {
}

export class MergeAllInnerSubscriber<T> extends Subscriber<T> {
constructor(destination: Observer<T>, private parent: MergeAllSubscriber<T>,
private innerSub: Subscription<T> ) {
constructor(destination: Observer<T>, private parent: MergeAllSubscriber<T>) {
super(destination);
}

_complete() {
this.parent.notifyComplete(this.innerSub);
this.parent.notifyComplete(this);
}
}

0 comments on commit d65e7ea

Please sign in to comment.