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

Method removeInternalAndSame

src/utils.ts:503–517  ·  view source on GitHub ↗

removes field from the first object if same as the second objects (like diffing) and internal '_' for saving

(a: unknown, b: unknown)

Source from the content-addressed store, hash-verified

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 {

Callers 2

saveMethod · 0.80
utils-spec.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected