Skip to content

Commit

Permalink
Used lodash operator
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht committed Oct 12, 2022
1 parent 19df4cd commit ff1698b
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions packages/database/test/helpers/syncpoint-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import assert from 'assert';
import { FirebaseApp, initializeApp } from '@firebase/app';
import { expect } from 'chai';
import * as chai from 'chai';
import _ from 'lodash';
import sinonChai from 'sinon-chai';

import {
Expand Down Expand Up @@ -72,37 +73,6 @@ function objectMap(object, mapFn) {
return newObj;
}

function unsafeClone(obj) {
if (!obj || typeof obj !== 'object') {
return obj;
}
if (typeof obj.clone === 'function') {
return obj.clone();
}
if (typeof Map !== 'undefined' && obj instanceof Map) {
return new Map(obj);
} else if (typeof Set !== 'undefined' && obj instanceof Set) {
return new Set(obj);
} else if (obj instanceof Date) {
return new Date(obj.getTime());
}
const clone = Array.isArray(obj)
? []
: typeof ArrayBuffer === 'function' &&
typeof ArrayBuffer.isView === 'function' &&
ArrayBuffer.isView(obj) &&
!(obj instanceof DataView)
? // @ts-ignore
new obj.constructor(obj.length)
: {};

// eslint-disable-next-line guard-for-in
for (const key in obj) {
clone[key] = unsafeClone(obj[key]);
}
return clone;
}

// eslint-disable-next-line @typescript-eslint/ban-types
function removeIf<T>(array: T[], callback: Function) {
let i = 0;
Expand Down Expand Up @@ -435,8 +405,8 @@ export class SyncPointTestParser {
const registrations = {};

for (let i = 0; i < testSpec.steps.length; ++i) {
// TODO: Create a separate object structure specifically for the steps.
const spec = unsafeClone(testSpec.steps[i]);
// TODO: Create a separate object structure specifically for the steps
const spec = _.cloneDeep(testSpec.steps[i]);
if ('.comment' in spec) {
console.log(' > ' + spec['.comment']);
}
Expand Down

0 comments on commit ff1698b

Please sign in to comment.