Skip to content

Commit

Permalink
fix(rstream): subscription generics if transducer is used
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 25, 2018
1 parent 898be34 commit 592a242
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions packages/rstream/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class Stream<T> extends Subscription<T, T>
this.src = src;
}

subscribe(sub: ISubscriber<T>, id?: string): Subscription<T, T>
subscribe<C>(xform: Transducer<T, C>, id?: string): Subscription<T, C>;
subscribe<C>(sub: ISubscriber<T>, xform: Transducer<T, C>, id?: string): Subscription<T, C>;
subscribe(sub: ISubscriber<T>, id?: string): Subscription<T, T>;
subscribe<C>(sub: ISubscriber<C>, xform: Transducer<T, C>, id?: string): Subscription<T, C>
subscribe(...args: any[]) {
const wrapped = super.subscribe.apply(this, args);
if (this.subs.length === 1) {
Expand All @@ -27,14 +27,6 @@ export class Stream<T> extends Subscription<T, T>
return wrapped;
}

transform<B>(xform: Transducer<T, B>, id?: string): Subscription<T, B> {
const wrapped = super.subscribe(xform, id);
if (this.subs.length === 1) {
this._cancel = (this.src && this.src(this)) || (() => void 0);
}
return wrapped;
}

unsubscribe(sub?: Subscription<T, any>) {
const res = super.unsubscribe(sub);
if (res && (!this.subs || !this.subs.length)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rstream/src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Subscription<A, B> implements

subscribe(sub: ISubscriber<B>, id?: string): Subscription<B, B>
subscribe<C>(xform: Transducer<B, C>, id?: string): Subscription<B, C>;
subscribe<C>(sub: ISubscriber<B>, xform: Transducer<B, C>, id?: string): Subscription<B, C>
subscribe<C>(sub: ISubscriber<C>, xform: Transducer<B, C>, id?: string): Subscription<B, C>
subscribe(...args: any[]) {
if (this.state < State.DONE) {
let sub, xform, id;
Expand Down

0 comments on commit 592a242

Please sign in to comment.