-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add mechanism for left shallow merge (#3849)
Refs #3845
- Loading branch information
Showing
6 changed files
with
114 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import mergeRight from './merge-right'; | ||
|
||
const mergeLeft = (...[sourceElement, targetElement, options]: Parameters<typeof mergeRight>) => { | ||
return mergeRight(targetElement, sourceElement, options); | ||
}; | ||
|
||
mergeLeft.all = (...[list, options]: Parameters<typeof mergeRight.all>) => { | ||
return mergeRight.all([...list].reverse(), options); | ||
}; | ||
|
||
export default mergeLeft; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { assert } from 'chai'; | ||
|
||
import { toValue, ObjectElement, mergeLeft } from '../../src'; | ||
|
||
/** | ||
* mergeLeft is just a specialization of mergeRight. We don't need tests here | ||
* as they would become redundant with mergeRight tests. | ||
*/ | ||
describe('mergeLeft', function () { | ||
it('should merge existing simple keys in target at the roots', function () { | ||
const source = new ObjectElement({ key1: 'changed', key2: 'value2' }); | ||
const target = new ObjectElement({ key1: 'value1', key3: 'value3' }); | ||
const merged = mergeLeft(target, source); | ||
const expected = { | ||
key1: 'value1', | ||
key2: 'value2', | ||
key3: 'value3', | ||
}; | ||
|
||
assert.deepEqual( | ||
toValue(target), | ||
{ key1: 'value1', key3: 'value3' }, | ||
'merge should be immutable', | ||
); | ||
assert.deepEqual(toValue(merged), expected); | ||
}); | ||
|
||
it('mergeLeft.all', function () { | ||
const source = new ObjectElement({ key1: 'changed', key2: 'value2' }); | ||
const target = new ObjectElement({ key1: 'value1', key3: 'value3' }); | ||
const merged = mergeLeft.all([target, source]); | ||
const expected = { | ||
key1: 'value1', | ||
key2: 'value2', | ||
key3: 'value3', | ||
}; | ||
|
||
assert.deepEqual( | ||
toValue(target), | ||
{ key1: 'value1', key3: 'value3' }, | ||
'merge should be immutable', | ||
); | ||
assert.deepEqual(toValue(merged), expected); | ||
}); | ||
}); |
This file contains 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