* 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)
| 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 { |
no test coverage detected