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

Skip to content

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