Created
January 13, 2019 02:41
-
-
Save cmstead/63c33175bdaec9321eb69069f88990cc to your computer and use it in GitHub Desktop.
Eliminating conditional blocks with value selection and assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function async saveDataOrDefault(todoId, messageRecord) { | |
if(messageRecord !== null) { | |
await dbModel.saveData(todoId, messageRecord); | |
} else { | |
await dbModel.saveData(todoId, { message: null }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMessageRecordOrDefault(messageRecord) { | |
return messageRecord === null ? { message: null } : messageRecord; | |
} | |
function async saveDataOrDefault(todoId, messageRecord) { | |
const cleanMessageRecord = getMessageRecordOrDefault(messageRecord); | |
await dbModel.saveData(todoId, cleanMessageRecord); | |
} |
martypdx
commented
Jan 14, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment