Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert('Cannot merge with a non-changeset', isChangeset(changeset));
assert('Cannot merge with a changeset of different content', get(changeset, CONTENT) === content);
if (get(this, 'isPristine') && get(changeset, 'isPristine')) {
return this;
}
let c1 /*: Changes */ = get(this, CHANGES);
let c2 /*: Changes */ = get(changeset, CHANGES);
let e1 /*: Errors */ = get(this, ERRORS);
let e2 /*: Errors */ = get(changeset, ERRORS);
let newChangeset /*: ChangesetDef */ = new Changeset(content, get(this, VALIDATOR));
let newErrors /*: Errors */ = objectWithout(keys(c2), e1);
let newChanges /*: Changes */ = objectWithout(keys(e2), c1);
let mergedErrors /*: Errors */ = mergeNested(newErrors, e2);
let mergedChanges /*: Changes */ = mergeNested(newChanges, c2);
newChangeset[ERRORS] = mergedErrors;
newChangeset[CHANGES] = mergedChanges;
newChangeset._notifyVirtualProperties();
return newChangeset;
},
assert('Cannot merge with a changeset of different content', get(changeset, CONTENT) === content);
if (get(this, 'isPristine') && get(changeset, 'isPristine')) {
return this;
}
let c1 /*: Changes */ = get(this, CHANGES);
let c2 /*: Changes */ = get(changeset, CHANGES);
let e1 /*: Errors */ = get(this, ERRORS);
let e2 /*: Errors */ = get(changeset, ERRORS);
let newChangeset /*: ChangesetDef */ = new Changeset(content, get(this, VALIDATOR));
let newErrors /*: Errors */ = objectWithout(keys(c2), e1);
let newChanges /*: Changes */ = objectWithout(keys(e2), c1);
let mergedErrors /*: Errors */ = mergeNested(newErrors, e2);
let mergedChanges /*: Changes */ = mergeNested(newChanges, c2);
newChangeset[ERRORS] = mergedErrors;
newChangeset[CHANGES] = mergedChanges;
newChangeset._notifyVirtualProperties();
return newChangeset;
},