Automate Updater.updateDictionaryDetails()'s process

This commit is contained in:
Robbie Antenesse 2017-08-20 23:24:57 -06:00
parent 1e8684e2a1
commit 3ae2114449
1 changed files with 10 additions and 31 deletions

View File

@ -22,42 +22,21 @@ export class Updater {
}); });
} }
updateDictionaryDetails (dicitonaryDetails = {}) { updateDictionaryDetails (dictionaryDetails = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const updatedDetails = {}; const updatedDetails = {};
if (dicitonaryDetails.name) { const detailKeys = ['consonants', 'vowels', 'blends', 'onset', 'nucleus', 'coda', 'exceptions'];
updatedDetails['name'] = dicitonaryDetails.name;
this.dictionary.name = dicitonaryDetails.name; for (const key in dictionaryDetails) {
this.dictionary[key] = dictionaryDetails[key];
if (!detailKeys.includes(key)) {
updatedDetails[key] = dictionaryDetails[key];
}
} }
if (dicitonaryDetails.specification) { if (Object.keys(dictionaryDetails).some(key => { return detailKeys.includes(key) })) {
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;
updatedDetails['details'] = this.dictionary.details; updatedDetails['details'] = this.dictionary.details;
} }