fix(single): predicate function receives indices starting at 0#2396
Merged
benlesh merged 1 commit intoReactiveX:masterfrom Feb 20, 2017
Merged
fix(single): predicate function receives indices starting at 0#2396benlesh merged 1 commit intoReactiveX:masterfrom
benlesh merged 1 commit intoReactiveX:masterfrom
Conversation
If the user is relying on indicies starting at 1 than this could be a BC. Otherwise now it's compatible with RxJS 4.
kwonoj
approved these changes
Feb 20, 2017
Member
|
For behavior of single, back then I was implementing unmatched one returned undefined (#322 (comment)) and discussed to update to throw Error instead. I assume I have specific path left without updating it then. |
benlesh
approved these changes
Feb 20, 2017
Contributor
Author
|
@kwonoj I read the discussion and if I understand it correctly it was agreed that it should throw an error instead of |
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using the predicate function in the
single()operator it passes indices starting at1instead of0.This prints to console:
Live demo: https://jsbin.com/raveji/2/edit?js,console
That's because it's first incremented (single.ts#L65) and then read again from property (single.ts#L75).
In RxJS 4 the indices start at
0(which is probably more expected behavior). Live demo: https://jsbin.com/qihaqur/3/edit?js,consoleIf the user is relying on indices starting at
1than this could be a BC. Otherwise now it's compatible with RxJS 4.There's one more inconsistency with RxJS 4.
When there's no item matching the predicate function the RxJS 4 version sends an error notification
EmptyError. Live demo: https://jsbin.com/pukikes/3/edit?js,consoleThis prints to console:
But the RxJS 5 implementation just emits
undefinedasnextand sendserroronly when thesingle()operator received no value at all (single.ts#L87).Live demo: https://jsbin.com/yavepan/2/edit?js,console.
The docblock for
single()says:This describes the RxJS 4 behavior but the RxJS 5 tests cover a use-case where
single()emitsundefinedsingle-spec.ts#L142. Also the two exception classes mentioned don't exist.So I'm wondering what's the correct behavior?