Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Subscriber): do not call complete with undefined value param #2559

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion spec/Subscriber-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Subscriber', () => {
});

it('should not be closed when other subscriber with same observer instance completes', () => {
let observer = {
const observer = {
next: function () { /*noop*/ }
};

Expand All @@ -97,4 +97,19 @@ describe('Subscriber', () => {
expect(sub1.closed).to.be.false;
expect(sub2.closed).to.be.true;
});

it('should call complete observer without any arguments', () => {
let argument: Array<any> = null;

const observer = {
complete: (...args: Array<any>) => {
argument = args;
}
};

const sub1 = new Subscriber(observer);
sub1.complete();

expect(argument).to.have.lengthOf(0);
});
});
6 changes: 4 additions & 2 deletions src/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@ class SafeSubscriber<T> extends Subscriber<T> {
if (!this.isStopped) {
const { _parentSubscriber } = this;
if (this._complete) {
const wrappedComplete = () => this._complete.call(this._context);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trxcllnt what about this approach? create one fn closure for complete only, and let __try... avoid any branching (if, or rest operator...). There is overhead to create one additional closure, but only for completion and will not impact next.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwonoj that looks great! I like how it removes the branching in the next case


if (!_parentSubscriber.syncErrorThrowable) {
this.__tryOrUnsub(this._complete);
this.__tryOrUnsub(wrappedComplete);
this.unsubscribe();
} else {
this.__tryOrSetError(_parentSubscriber, this._complete);
this.__tryOrSetError(_parentSubscriber, wrappedComplete);
this.unsubscribe();
}
} else {
Expand Down