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(pipe): Special handling for 0-arg case. #4936

Merged
merged 5 commits into from Apr 3, 2020
Merged

Conversation

leewz
Copy link
Contributor

@leewz leewz commented Jul 27, 2019

Optimize calling pipe with 0 args.

Closes #4933

There is an if (!fns) check in the pipeFromArray helper, and it results in noop. The test for pipe says the 0-arg case returns a no-op, but it checks for identity. The test is probably meant to test for that check, but the check is for the lack of an args array, so I added a check for that test to test and fixed the test's label.

The if (!fns) check might not be necessary at all. It is unreachable from client code, since pipeFromArray is internal, and is only used from pipe, which will never pass null/undefined.

@leewz
Copy link
Contributor Author

leewz commented Jul 27, 2019 via email

@cartant
Copy link
Collaborator

cartant commented Jul 27, 2019

The right predictable behavior may be to throw an error.

I'm fine with it throwing an error. I just don't think it should return a no-op.

Given that the type signature requires an array to be passed, I think removing the entire if (!fns) statement. If fns is undefined or null, it will throw when fns.length is evaluated. And that's fine by me.

The check is never reached in internal code, and is not exported for
external code. The behavior is not tested for, and arguably wrong.
@leewz
Copy link
Contributor Author

leewz commented Jul 27, 2019

Removed the check for nonexistent array argument.

Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

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

LGTM

@benlesh
Copy link
Member

benlesh commented Aug 9, 2019

Oh, I see, we wanted to keep the error on the fn.length call in that case ... I'll revert my change. It's a weird corner case anyhow.

@benlesh benlesh merged commit 290fa51 into ReactiveX:master Apr 3, 2020
benlesh added a commit that referenced this pull request Apr 3, 2020
* fix(pipe): Special handling for 0 args.

* test(pipe): Fix test label for 0-arg.

* fix(pipe): Remove check for missing args array.

The check is never reached in internal code, and is not exported for
external code. The behavior is not tested for, and arguably wrong.

* fix(pipe): no argument case run-time check

* refactor: revert checking for lack of array argument

Co-authored-by: Ben Lesh <ben@benlesh.com>
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
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.

Nitpick: Shouldn't Rx.pipe with no arguments return identity instead of noop?
3 participants