Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix collection size check in merge #1521

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

Merged
merged 1 commit into from
May 15, 2018

Conversation

acusti
Copy link
Contributor

@acusti acusti commented May 9, 2018

Fixes #1490

Records can have a size property (collection.size, in the existing code) that is independent of the calculated immutable Collection size property; using toSeq() ensures that the Collection.size property is checked instead. Also added a test case to verify the edge case that this resolves.

In debugging the original issue, I found that adding return this; to the end of the RecordType function in Record.js (https://github.com/facebook/immutable-js/blob/master/src/Record.js#L76) also deals with #1490. This is because that function was getting erroneously invoked from mergeIntoKeyedWith when called on a record with {size: 0} from return collection.constructor(iters[0]);, and adding the final return ensures that collection.constructor(iters[0]) still returns the correct thing. I wasn’t sure if there is any other code path that could lead to that function being invoked with the expectation of getting the record instance returned, but if so, I’d be happy to add the final return this; to this PR.

Records can have a size property (`collection.size`, in this
conditional) that is independent of the Collection.size property; using
toSeq() ensures that the Collection.size property is checked instead
@kozlitinaelja kozlitinaelja merged commit a22ece7 into immutable-js:master May 15, 2018
@acusti acusti deleted the record-size-merge branch March 31, 2022 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Immutable.Record with a "size" key causes "merge" commands to fail
3 participants