1- import isNil from 'lodash.isnil'
2-
31const CUSTOM = 'custom'
42
53/**
@@ -11,7 +9,7 @@ const CUSTOM = 'custom'
119 * @returns {Array } Ordered Array [oldObj, newObj]
1210 */
1311export default function copyEmptyArrayProps ( oldObj = { } , newObj = { } ) {
14- if ( ! isNil ( oldObj ) && ! isNil ( newObj ) ) {
12+ if ( oldObj && newObj ) {
1513 const nextObjectWithEmptyArray = Object . entries ( oldObj ) . reduce (
1614 ( merged , [ key , value ] ) => {
1715 // Ignore CUSTOM key as this object is dynamic and its up to the user to dynamically change it
@@ -26,13 +24,13 @@ export default function copyEmptyArrayProps(oldObj = {}, newObj = {}) {
2624 } , { } )
2725 for ( let i = 0 ; i < newObj [ key ] . length ; i ++ ) {
2826 if (
29- ! isNil ( newObj [ key ] [ i ] ) &&
27+ newObj [ key ] [ i ] &&
3028 typeof newObj [ key ] [ i ] === 'object' &&
31- ! isNil ( newObj [ key ] [ i ] . id )
29+ newObj [ key ] [ i ] . id
3230 ) {
3331 // Since its unordered array elements then check if the element on `oldObj` exists by id
3432 const foundObject = hashMapValue [ newObj [ key ] [ i ] . id ]
35- if ( ! isNil ( foundObject ) ) {
33+ if ( foundObject ) {
3634 const [ , nestedObject ] = copyEmptyArrayProps (
3735 foundObject ,
3836 newObj [ key ] [ i ]
@@ -50,11 +48,11 @@ export default function copyEmptyArrayProps(oldObj = {}, newObj = {}) {
5048 return merged
5149 }
5250 if ( Array . isArray ( value ) ) {
53- merged [ key ] = isNil ( newObj [ key ] ) ? [ ] : newObj [ key ]
51+ merged [ key ] = newObj [ key ] ? newObj [ key ] : [ ]
5452 return merged
5553 }
5654 if (
57- ! isNil ( newObj [ key ] ) &&
55+ newObj [ key ] &&
5856 typeof value === 'object' &&
5957 // Ignore Date as this will create invalid object since typeof date === 'object' return true
6058 // ex: {date: new Date()} will result {date: {}}
0 commit comments