MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / cloneDeep

Method cloneDeep

src/utils.ts:628–640  ·  view source on GitHub ↗

* Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY. * Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.

(obj: T)

Source from the content-addressed store, hash-verified

626 * Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
627 */
628 static cloneDeep<T>(obj: T): T {
629 // list of fields we will skip during cloneDeep (nested objects, other internal)
630 const skipFields = ['parentGrid', 'el', 'grid', 'subGrid', 'engine'];
631 // return JSON.parse(JSON.stringify(obj)); // doesn't work with date format ?
632 const ret = Utils.clone(obj);
633 for (const key in ret) {
634 // NOTE: we don't support function/circular dependencies so skip those properties for now...
635 if (ret.hasOwnProperty(key) && typeof(ret[key]) === 'object' && key.substring(0, 2) !== '__' && !skipFields.find(k => k === key)) {
636 ret[key] = Utils.cloneDeep(obj[key]);
637 }
638 }
639 return ret;
640 }
641
642 /** deep clone the given HTML node, removing teh unique id field */
643 public static cloneNode(el: HTMLElement): HTMLElement {

Callers 7

initMethod · 0.80
initAllMethod · 0.80
constructorMethod · 0.80
makeSubGridMethod · 0.80
saveMethod · 0.80
updateMethod · 0.80
utils-spec.tsFile · 0.80

Calls 2

cloneMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected