removes field from the first object if same as the second objects (like diffing) and internal '_' for saving
(a: unknown, b: unknown)
| 501 | |
| 502 | /** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */ |
| 503 | static removeInternalAndSame(a: unknown, b: unknown):void { |
| 504 | if (typeof a !== 'object' || typeof b !== 'object') return; |
| 505 | // skip arrays as we don't know how to hydrate them (unlike object spread operator) |
| 506 | if (Array.isArray(a) || Array.isArray(b)) return; |
| 507 | for (let key in a) { |
| 508 | const aVal = a[key]; |
| 509 | const bVal = b[key]; |
| 510 | if (key[0] === '_' || aVal === bVal) { |
| 511 | delete a[key] |
| 512 | } else if (aVal && typeof aVal === 'object' && bVal !== undefined) { |
| 513 | Utils.removeInternalAndSame(aVal, bVal); |
| 514 | if (!Object.keys(aVal).length) { delete a[key] } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | /** removes internal fields '_' and default values for saving */ |
| 520 | static removeInternalForSave(n: GridStackNode, removeEl = true): void { |
no outgoing calls
no test coverage detected