8000 throw error in mergeWith method if no merger is passed (#1543) · immutable-js/immutable-js@2ea44e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ea44e0

Browse files
committed
throw error in mergeWith method if no merger is passed (#1543)
Fixes #1503 Squashed commit of the following: commit a5091619058844f6bfc758f9111a34e17d72bc09 Author: Lee Byron <lee.byron@robinhood.com> Date: Tue Sep 18 11:59:46 2018 -0700 Refinements commit 4d04397435ec323bd9f8e598b651acf45ee683fe Merge: 37ae5be df8b50a Author: Lee Byron <lee.byron@robinhood.com> Date: Tue Sep 18 11:46:51 2018 -0700 Merge branch 'master' of https://github.com/Brantron/immutable-js into Brantron-master commit df8b50a Author: Brandon Lawrence <brandon.lawrence@contactually.com> Date: Sun Jul 15 19:48:19 2018 -0400 merge vs concat when possible in functional/merge commit 2916161 Author: Brandon Lawrence <brandon.lawrence@contactually.com> Date: Fri Jun 15 07:39:22 2018 -0400 throw error in mergeWith method if no merger is passed (#1503)
1 parent 37ae5be commit 2ea44e0

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

__tests__/merge.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ describe('merge', () => {
4040
);
4141
});
4242

43+
it('throws typeError without merge function', () => {
44+
const m1 = Map({ a: 1, b: 2, c: 3 });
45+
const m2 = Map({ d: 10, b: 20, e: 30 });
46+
expect(() => m1.mergeWith(1, m2)).toThrowError(TypeError);
47+
});
48+
4349
it('provides key as the third argument of merge function', () => {
4450
const m1 = Map({ id: 'temp', b: 2, c: 3 });
4551
const m2 = Map({ id: 10, b: 20, e: 30 });

src/functional/merge.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ export function mergeWithSources(collection, sources, merger) {
3838
);
3939
}
4040
if (isImmutable(collection)) {
41-
return collection.mergeWith
41+
return typeof merger === 'function' && collection.mergeWith
4242
? collect 8000 ion.mergeWith(merger, ...sources)
43-
: collection.concat(...sources);
43+
: collection.merge
44+
? collection.merge(...sources)
45+
: collection.concat(...sources);
4446
}
4547
const isArray = Array.isArray(collection);
4648
let merged = collection;

src/methods/merge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export function merge(...iters) {
1414
}
1515

1616
export function mergeWith(merger, ...iters) {
17+
if (typeof merger !== 'function') {
18+
throw new TypeError('Invalid merger function: ' + merger);
19+
}
1720
return mergeIntoKeyedWith(this, iters, merger);
1821
}
1922

0 commit comments

Comments
 (0)
0