Skip to content

Commit 2b0880a

Browse files
committed
merge/union dont work correctly inside withMutations when the mutable is empty.
Fixes immutable-js#405
1 parent da9d87d commit 2b0880a

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

__tests__/Set.ts

+8
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ describe('Set', () => {
198198
expect(Immutable.is(s1, v1)).toBe(false);
199199
});
200200

201+
it('can use union in a withMutation', () => {
202+
var js = Immutable.Set().withMutations(set => {
203+
set.union([ 'a' ]);
204+
set.add('b');
205+
}).toJS();
206+
expect(js).toEqual(['a', 'b']);
207+
});
208+
201209
// TODO: more tests
202210

203211
});

dist/immutable.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@
24562456
if (iters.length === 0) {
24572457
return collection;
24582458
}
2459-
if (collection.size === 0 && iters.length === 1) {
2459+
if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
24602460
return collection.constructor(iters[0]);
24612461
}
24622462
return collection.withMutations(function(collection ) {
@@ -3559,7 +3559,7 @@
35593559
if (iters.length === 0) {
35603560
return this;
35613561
}
3562-
if (this.size === 0 && iters.length === 1) {
3562+
if (this.size === 0 && !this.__ownerID && iters.length === 1) {
35633563
return this.constructor(iters[0]);
35643564
}
35653565
return this.withMutations(function(set ) {

0 commit comments

Comments
 (0)