From 3ae211444959898070c0f61b2081407c63e79dce Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Sun, 20 Aug 2017 23:24:57 -0600 Subject: [PATCH] Automate Updater.updateDictionaryDetails()'s process --- src/managers/Updater.js | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/src/managers/Updater.js b/src/managers/Updater.js index 4fbd114..bcea189 100644 --- a/src/managers/Updater.js +++ b/src/managers/Updater.js @@ -22,42 +22,21 @@ export class Updater { }); } - updateDictionaryDetails (dicitonaryDetails = {}) { + updateDictionaryDetails (dictionaryDetails = {}) { return new Promise((resolve, reject) => { const updatedDetails = {}; - if (dicitonaryDetails.name) { - updatedDetails['name'] = dicitonaryDetails.name; - this.dictionary.name = dicitonaryDetails.name; + const detailKeys = ['consonants', 'vowels', 'blends', 'onset', 'nucleus', 'coda', 'exceptions']; + + for (const key in dictionaryDetails) { + this.dictionary[key] = dictionaryDetails[key]; + + if (!detailKeys.includes(key)) { + updatedDetails[key] = dictionaryDetails[key]; + } } - if (dicitonaryDetails.specification) { - updatedDetails['specification'] = dicitonaryDetails.specification; - this.dictionary.specification = dicitonaryDetails.specification; - } - - if (dicitonaryDetails.description) { - updatedDetails['description'] = dicitonaryDetails.description; - this.dictionary.description = dicitonaryDetails.description; - } - - if (dicitonaryDetails.partsOfSpeech) { - updatedDetails['partsOfSpeech'] = dicitonaryDetails.partsOfSpeech; - this.dictionary.partsOfSpeech = dicitonaryDetails.partsOfSpeech; - } - - if (dicitonaryDetails.consonants) { - this.dictionary.consonants = dicitonaryDetails.consonants; - updatedDetails['details'] = this.dictionary.details; - } - - if (dicitonaryDetails.vowels) { - this.dictionary.vowels = dicitonaryDetails.vowels; - updatedDetails['details'] = this.dictionary.details; - } - - if (dicitonaryDetails.blends) { - this.dictionary.blends = dicitonaryDetails.blends; + if (Object.keys(dictionaryDetails).some(key => { return detailKeys.includes(key) })) { updatedDetails['details'] = this.dictionary.details; }