All files / src/app/store/util deep-clone.ts

100% Statements 15/15
83.33% Branches 5/6
100% Functions 2/2
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  1x   1208x 113x 113x 182x 182x   113x   1095x 836x 836x 860x 860x 860x     836x     259x    
 
export function deepClone(state) {
 
  if (Array.isArray(state)) {
    const newState = [];
    for (let index = 0; index < state.length; index++) {
      const element = state[index];
        newState[index] = deepClone(element);
    }
    return newState;
  };
  if (typeof state === 'object') {
    const newState = {...state};
    Object.keys(newState).forEach(key => {
      Eif (newState.hasOwnProperty(key)) {
        const val = newState[key];
        newState[key] = deepClone(val);
      }
    });
    return newState;
  };
 
  return state;
};