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(bindCallback): emit undefined when callback is without arguments #2328

Merged
merged 1 commit into from
Feb 14, 2017
Merged

fix(bindCallback): emit undefined when callback is without arguments #2328

merged 1 commit into from
Feb 14, 2017

Conversation

mpodlasin
Copy link
Contributor

Description
Related to issue #2254 in bindNodeCallback. It turns out bindCallback has the same problem:

When wrapped function calls its callback without any arguments, resulting Observable will emit empty array, intead of undefined.

function callback(cb) {
   cb();
}

Observable.bindCallback(callback)
.subscribe(value => console.log(value)); // value is []

In RxJS 4 in fromCalllback resulting Observable emits undefined as seen here:
https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/perf/operators/fromcallback.js#L20-L21
(when array is empty, calling results[0] results in undefined, which is emitted).

Related to
#2254

In resulting Observable emit undefined when callback is called without
parameters, instead of emitting empty array.
@coveralls
Copy link

coveralls commented Feb 6, 2017

Coverage Status

Coverage remained the same at 97.689% when pulling 915a2a8 on Podlas29:bind-callback-no-callback-arguments into 6ce4773 on ReactiveX:master.

Copy link
Member

@kwonoj kwonoj left a comment

Choose a reason for hiding this comment

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

Change looks ok to me.

@@ -15,6 +15,7 @@ export class BoundCallbackObservable<T> extends Observable<T> {
subject: AsyncSubject<T>;

/* tslint:disable:max-line-length */
static create(callbackFunc: (callback: () => any) => any, selector?: void, scheduler?: IScheduler): () => Observable<void>;
Copy link
Member

Choose a reason for hiding this comment

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

It's not related to this PR, but I just noticed bindNodeCallback doesn't have corresponding overloading signatures. Maybe we need this? /cc @david-driscoll

Copy link
Contributor Author

@mpodlasin mpodlasin Feb 6, 2017

Choose a reason for hiding this comment

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

Now that I think about it, I have seen some operators have type-only tests. Maybe I should add such tests here?

Copy link
Member

Choose a reason for hiding this comment

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

No, that is intended for specific cases if current test case doesn't covers it. it is worth to create those and it'll be appreciated, but I'd like to suggest to separate with this PR since each has different scope.

@jayphelps jayphelps merged commit 1d27ea2 into ReactiveX:master Feb 14, 2017
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants