LearnNewsExamplesServices
Frontmatter
id245
titleautoGenerateGetSet() => set() => break if beforeSet has no return value
stateClosed
labels
enhancement
assignees[]
createdAtFeb 25, 2020, 12:17 PM
updatedAtFeb 25, 2020, 12:20 PM
githubUrlhttps://github.com/neomjs/neo/issues/245
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtFeb 25, 2020, 12:20 PM

autoGenerateGetSet() => set() => break if beforeSet has no return value

tobiu
tobiu commented on Feb 25, 2020, 12:17 PM

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.

tobiu added the enhancement label on Feb 25, 2020, 12:17 PM
tobiu referenced in commit f2f1f37 - "autoGenerateGetSet() => set() => break if beforeSet has no return value #245" on Feb 25, 2020, 12:19 PM
tobiu
tobiu Feb 25, 2020, 12:20 PM

done.

tobiu closed this issue on Feb 25, 2020, 12:20 PM