Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) /*: T | ErrLike */ {
let changes /*: Changes */ = get(this, CHANGES);
let isValid /*: boolean */ = validation === true
|| isArray(validation)
&& validation.length === 1
&& (validation /*: any */)[0] === true;
// Shorthand for `this`.
let c /*: ChangesetDef */ = this;
// Happy path: remove `key` from error map.
c._deleteKey(ERRORS, key);
// Happy path: update change map.
if (!isEqual(oldValue, value)) {
setNestedProperty(changes, key, new Change(value));
} else if (key in changes) {
c._deleteKey(CHANGES, key);
}
// Happy path: notify that `key` was added.
c.notifyPropertyChange(CHANGES);
c.notifyPropertyChange(key);
// Error case.
if (!isValid) {
let v /*: ValidationErr */ = (validation /*: any */);
return c.addError(key, { value, validation: v });
}
// Return new value.
return value;
let newChanges /*: Changes */ = keys(preparedChanges).reduce((newObj, key) => {
newObj[key] = new Change(preparedChanges[key]);
return newObj;
}, {});