Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
prepare(
prepareChangesFn /*: ({ [string]: mixed }) => ({ [string]: mixed }) */
) /*: ChangesetDef */ {
let changes /*: { [string]: mixed } */ = get(this, '_bareChanges');
let preparedChanges = prepareChangesFn(changes);
assert('Callback to `changeset.prepare` must return an object', isObject(preparedChanges));
validateNestedObj('preparedChanges', preparedChanges);
let newChanges /*: Changes */ = keys(preparedChanges).reduce((newObj, key) => {
newObj[key] = new Change(preparedChanges[key]);
return newObj;
}, {});
set(this, CHANGES, newChanges);
return this;
},
restore({ changes, errors } /*: Snapshot */) /*: ChangesetDef */ {
validateNestedObj('snapshot.changes', changes);
validateNestedObj('snapshot.errors', errors);
let newChanges /*: Changes */ = keys(changes).reduce((newObj, key) => {
newObj[key] = new Change(changes[key]);
return newObj;
}, {});
let newErrors /*: Errors */ = keys(errors).reduce((newObj, key) => {
let e /*: ErrLike<*> */ = errors[key];
newObj[key] = new Err(e.value, e.validation);
return newObj;
}, {});
set(this, CHANGES, newChanges);
set(this, ERRORS, newErrors);
(this /*: ChangesetDef */)._notifyVirtualProperties();
restore({ changes, errors } /*: Snapshot */) /*: ChangesetDef */ {
validateNestedObj('snapshot.changes', changes);
validateNestedObj('snapshot.errors', errors);
let newChanges /*: Changes */ = keys(changes).reduce((newObj, key) => {
newObj[key] = new Change(changes[key]);
return newObj;
}, {});
let newErrors /*: Errors */ = keys(errors).reduce((newObj, key) => {
let e /*: ErrLike<*> */ = errors[key];
newObj[key] = new Err(e.value, e.validation);
return newObj;
}, {});
set(this, CHANGES, newChanges);
set(this, ERRORS, newErrors);