@@ -2,88 +2,83 @@ import { is, isPlain } from './is'
22import forEachObject from './forEachObject'
33
44// https://jsperf.com/merge-challenge
5- export default function merge ( destiny , origin ) {
5+ export default function merge ( target , patch ) {
66 const args = arguments
77 if ( args . length > 2 ) {
8- // Remove the destiny 2 arguments of the arguments and add thoose arguments as merged at the begining
9- Array . prototype . splice . call (
10- args ,
11- 0 ,
12- 2 ,
13- merge . call ( this , destiny , origin )
14- )
8+ // Remove the target 2 arguments of the arguments and add thoose arguments as merged at the begining
9+ Array . prototype . splice . call ( args , 0 , 2 , merge . call ( this , target , patch ) )
1510 // Recursion
1611 return merge . apply ( this , args )
17- } else if ( origin === destiny ) {
18- return destiny
12+ } else if ( patch === target ) {
13+ return target
1914 } else {
20- forEachObject ( origin , destiny , mergeMutator )
21- return destiny
15+ forEachObject ( patch , target , mergeMutator )
16+ return target
2217 }
2318}
2419
25- export function mergeMutator ( { origin , destiny , prop } ) {
26- const origin_value = origin [ prop ]
27- const destiny_value = destiny [ prop ]
20+ export function mergeMutator ( { patch , target , prop } ) {
21+ const origin_value = patch [ prop ]
22+ const destiny_value = target [ prop ]
2823 const tof_origin = is ( origin_value )
2924 const tof_destiny = is ( destiny_value )
3025 if ( isPlain ( origin_value ) ) {
31- if ( ! destiny . hasOwnProperty ( prop ) || tof_origin != tof_destiny ) {
32- destiny [ prop ] = tof_origin == 'array' ? [ ] : { }
26+ if ( ! target . hasOwnProperty ( prop ) || tof_origin != tof_destiny ) {
27+ target [ prop ] = tof_origin == 'array' ? [ ] : { }
3328 }
3429 } else {
35- destiny [ prop ] = origin_value
30+ target [ prop ] = origin_value
3631 return false // we dont go deeper
3732 }
3833}
3934
40- // export default createCustomMerge('merge', ({ origin, destiny , prop }) => {
41- // const origin_value = origin [prop]
42- // const destiny_value = destiny [prop]
35+ // export default createCustomMerge('merge', ({ patch, target , prop }) => {
36+ // const origin_value = patch [prop]
37+ // const destiny_value = target [prop]
4338// const tof_origin = is(origin_value)
4439// const tof_destiny = is(destiny_value)
4540// if (isPlain(origin_value)) {
46- // if (!destiny .hasOwnProperty(prop) || tof_origin !== tof_destiny) {
47- // destiny [prop] = tof_origin === 'array' ? [] : {}
41+ // if (!target .hasOwnProperty(prop) || tof_origin !== tof_destiny) {
42+ // target [prop] = tof_origin === 'array' ? [] : {}
4843// if (tof_origin === 'array') {
4944// const array = []
5045// if (tof_destiny === 'object') {
5146// Object.keys(destiny_value)
5247// .filter(key => !isNaN(Number(key)))
5348// .forEach(key => (array[key] = destiny_value[key]))
5449// }
55- // destiny [prop] = array
50+ // target [prop] = array
5651// } else {
57- // destiny [prop] = {}
52+ // target [prop] = {}
5853// }
5954// }
60- // } else if (tof_origin === 'undefined' && destiny .hasOwnProperty(prop)) {
55+ // } else if (tof_origin === 'undefined' && target .hasOwnProperty(prop)) {
6156// //skipping
6257// } else {
63- // destiny [prop] = origin_value
58+ // target [prop] = origin_value
6459// return true // skipping
6560// }
6661// })
6762
6863// // https://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript
6964// export default function createCustomMerge(function_name, mutator) {
70- // return createFunction(function_name, function recursive(destiny, origin ) {
65+ // return createFunction(function_name, function recursive(target, patch ) {
7166// const args = arguments
7267// if (args.length > 2) {
73- // // Remove the destiny 2 arguments of the arguments and add thoose arguments as recursived at the begining
68+ // // Remove the target 2 arguments of the arguments and add thoose arguments as recursived at the begining
7469// Array.prototype.splice.call(
7570// args,
7671// 0,
7772// 2,
78- // recursive.call(this, destiny, origin )
73+ // recursive.call(this, target, patch )
7974// )
8075// // Recursion
8176// return recursive.apply(this, args)
82- // } else if (origin === destiny ) {
83- // return destiny
77+ // } else if (patch === target ) {
78+ // return target
8479// } else {
85- // forEachObject(origin , mutator, destiny )
86- // return destiny
80+ // forEachObject(patch , mutator, target )
81+ // return target
8782// }
8883// })
8984// }
0 commit comments