Valeriia Ruban 663a5642c2
[UI]: update Ember to 3.27 (#16227)
* Upgrade to 3.25 via ember-cli-update

* v3.25.3...v3.26.1

* v3.26.1...v3.27.0


Co-authored-by: Michael Klein <michael@firstiwaslike.com>
2023-02-10 13:32:19 -08:00

46 lines
1.4 KiB
JavaScript

/* eslint-disable no-prototype-builtins */
import { get } from '@ember/object';
export default function validateSometimes(validator, condition) {
return guardValidatorWithCondition(validator);
function guardValidatorWithCondition(validator) {
return function (key, newValue, oldValue, changes, content) {
let thisValue = {
get(property) {
if (property.includes('.')) {
let changesValue = get(changes, property);
if (typeof changesValue !== 'undefined') {
return changesValue;
}
// Check if the `changes` value is explicitly undefined,
// or if it's not present at all.
let pathSegments = property.split('.');
let propName = pathSegments.pop();
let objPath = pathSegments.join('.');
let obj = get(changes, objPath);
if (obj && obj.hasOwnProperty && obj.hasOwnProperty(propName)) {
return changesValue;
}
return get(content, property);
}
if (changes.hasOwnProperty(property)) {
return get(changes, property);
} else {
return get(content, property);
}
},
};
if (condition.call(thisValue, changes, content)) {
return validator(key, newValue, oldValue, changes, content);
}
return true;
};
}
}