see #242 (Nige)
if (me[beforeSet] && typeof me[beforeSet] === 'function') {
value = me[beforeSet](value, oldValue);
// If they don't return a value, that means no change
if (value === undefined) {
return;
}
}
The idea is eg
beforeSetStartDate(newDate, oldDate) {
if (typeof newDate === 'string') {
newDate = DateHelper.parse('YYYY-MM-DD');
}
// Only return a value if it's a *valid* value (!isNaN) and is actually changed.
// undefined return value means the change is vetoed - the calling code returns early.
if (!isNaN(newDate) && (!oldDate || oldDate.valueOf() !== newDate.valueOf())) {
return newDate;
}
}
Without the change, each beforeSet method with if conditions would need something like
else {
return oldValue;
}
so it might shorten the app code a little bit. I will give it a try, although return undefined; might cause issues in case it ever happens.
see #242 (Nige)
if (me[beforeSet] && typeof me[beforeSet] === 'function') { value = me[beforeSet](value, oldValue); // If they don't return a value, that means no change if (value === undefined) { return; } }The idea is eg
beforeSetStartDate(newDate, oldDate) { if (typeof newDate === 'string') { newDate = DateHelper.parse('YYYY-MM-DD'); } // Only return a value if it's a *valid* value (!isNaN) and is actually changed. // undefined return value means the change is vetoed - the calling code returns early. if (!isNaN(newDate) && (!oldDate || oldDate.valueOf() !== newDate.valueOf())) { return newDate; } }Without the change, each beforeSet method with if conditions would need something like
else { return oldValue; }so it might shorten the app code a little bit. I will give it a try, although
return undefined;might cause issues in case it ever happens.