Add DictionaryData.storedData getter+setter to make using the localstorage data

This commit is contained in:
Robbie Antenesse 2018-01-07 16:36:30 -07:00
parent a2063644af
commit 2a2db90555
1 changed files with 71 additions and 63 deletions

View File

@ -55,7 +55,7 @@ class DictionaryData {
} }
if (!store.get('Lexiconga')) { if (!store.get('Lexiconga')) {
store.set('Lexiconga', defaultDictionary); this.storedData = defaultDictionary;
} else { } else {
wordDb.words wordDb.words
.orderBy('id').reverse() .orderBy('id').reverse()
@ -73,270 +73,278 @@ class DictionaryData {
} }
} }
get storedData () {
return store.get('Lexiconga');
}
set storedData (updatedValues) {
store.set('Lexiconga', updatedValues);
}
get name () { get name () {
return store.get('Lexiconga').name return this.storedData.name
|| defaultDictionary.name; || defaultDictionary.name;
} }
set name (value) { set name (value) {
assert(typeof value === 'string', 'Name must be passed as a string.'); assert(typeof value === 'string', 'Name must be passed as a string.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.name = value.trim(); updatedValues.name = value.trim();
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get specification () { get specification () {
return store.get('Lexiconga').specification return this.storedData.specification
|| defaultDictionary.specification; || defaultDictionary.specification;
} }
set specification (value) { set specification (value) {
assert(typeof value === 'string', 'Specification must be passed as a string.'); assert(typeof value === 'string', 'Specification must be passed as a string.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.specification = value.trim(); updatedValues.specification = value.trim();
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get description () { get description () {
return store.get('Lexiconga').description return this.storedData.description
|| defaultDictionary.description; || defaultDictionary.description;
} }
set description (value) { set description (value) {
assert(typeof value === 'string', 'Description must be passed as a string.'); assert(typeof value === 'string', 'Description must be passed as a string.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.description = value.trim(); updatedValues.description = value.trim();
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get partsOfSpeech () { get partsOfSpeech () {
return store.get('Lexiconga').partsOfSpeech return this.storedData.partsOfSpeech
|| defaultDictionary.partsOfSpeech; || defaultDictionary.partsOfSpeech;
} }
set partsOfSpeech (array) { set partsOfSpeech (array) {
assert(Array.isArray(array), 'Parts of Speech must be passed as an array'); assert(Array.isArray(array), 'Parts of Speech must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.partsOfSpeech = array updatedValues.partsOfSpeech = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get details () { get details () {
return store.get('Lexiconga').details return this.storedData.details
|| defaultDictionary.details; || defaultDictionary.details;
} }
get consonants () { get consonants () {
return store.get('Lexiconga').details.phonology.consonants return this.storedData.details.phonology.consonants
|| defaultDictionary.details.phonology.consonants; || defaultDictionary.details.phonology.consonants;
} }
set consonants (array) { set consonants (array) {
assert(Array.isArray(array), 'Consonants must be passed as an array'); assert(Array.isArray(array), 'Consonants must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.consonants = array updatedValues.details.phonology.consonants = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get vowels () { get vowels () {
return store.get('Lexiconga').details.phonology.vowels return this.storedData.details.phonology.vowels
|| defaultDictionary.details.phonology.vowels; || defaultDictionary.details.phonology.vowels;
} }
set vowels (array) { set vowels (array) {
assert(Array.isArray(array), 'Vowels must be passed as an array'); assert(Array.isArray(array), 'Vowels must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.vowels = array updatedValues.details.phonology.vowels = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get blends () { get blends () {
return store.get('Lexiconga').details.phonology.blends return this.storedData.details.phonology.blends
|| defaultDictionary.details.phonology.blends; || defaultDictionary.details.phonology.blends;
} }
set blends (array) { set blends (array) {
assert(Array.isArray(array), 'Blends must be passed as an array'); assert(Array.isArray(array), 'Blends must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.blends = array updatedValues.details.phonology.blends = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get onset () { get onset () {
return store.get('Lexiconga').details.phonology.phonotactics.onset return this.storedData.details.phonology.phonotactics.onset
|| defaultDictionary.details.phonology.phonotactics.onset; || defaultDictionary.details.phonology.phonotactics.onset;
} }
set onset (array) { set onset (array) {
assert(Array.isArray(array), 'Onset must be passed as an array'); assert(Array.isArray(array), 'Onset must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.phonotactics.onset = array updatedValues.details.phonology.phonotactics.onset = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get nucleus () { get nucleus () {
return store.get('Lexiconga').details.phonology.phonotactics.nucleus return this.storedData.details.phonology.phonotactics.nucleus
|| defaultDictionary.details.phonology.phonotactics.nucleus; || defaultDictionary.details.phonology.phonotactics.nucleus;
} }
set nucleus (array) { set nucleus (array) {
assert(Array.isArray(array), 'Nucleus must be passed as an array'); assert(Array.isArray(array), 'Nucleus must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.phonotactics.nucleus = array updatedValues.details.phonology.phonotactics.nucleus = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get coda () { get coda () {
return store.get('Lexiconga').details.phonology.phonotactics.coda return this.storedData.details.phonology.phonotactics.coda
|| defaultDictionary.details.phonology.phonotactics.coda; || defaultDictionary.details.phonology.phonotactics.coda;
} }
set coda (array) { set coda (array) {
assert(Array.isArray(array), 'Coda must be passed as an array'); assert(Array.isArray(array), 'Coda must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.phonotactics.coda = array updatedValues.details.phonology.phonotactics.coda = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get exceptions () { get exceptions () {
return store.get('Lexiconga').details.phonology.phonotactics.exceptions return this.storedData.details.phonology.phonotactics.exceptions
|| defaultDictionary.details.phonology.phonotactics.exceptions; || defaultDictionary.details.phonology.phonotactics.exceptions;
} }
set exceptions (value) { set exceptions (value) {
assert(typeof value === 'string', 'Exceptions must be passed as a string.'); assert(typeof value === 'string', 'Exceptions must be passed as a string.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.phonology.phonotactics.exceptions = value.trim(); updatedValues.details.phonology.phonotactics.exceptions = value.trim();
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get orthographyNotes () { get orthographyNotes () {
return store.get('Lexiconga').details.orthography.notes return this.storedData.details.orthography.notes
|| defaultDictionary.details.orthography.notes; || defaultDictionary.details.orthography.notes;
} }
set orthographyNotes (value) { set orthographyNotes (value) {
assert(typeof value === 'string', 'Orthography Notes must be passed as a string.'); assert(typeof value === 'string', 'Orthography Notes must be passed as a string.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.orthography.notes = value.trim(); updatedValues.details.orthography.notes = value.trim();
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get grammarNotes () { get grammarNotes () {
return store.get('Lexiconga').details.grammar.notes return this.storedData.details.grammar.notes
|| defaultDictionary.details.grammar.notes; || defaultDictionary.details.grammar.notes;
} }
set grammarNotes (value) { set grammarNotes (value) {
assert(typeof value === 'string', 'Grammar Notes must be passed as a string.'); assert(typeof value === 'string', 'Grammar Notes must be passed as a string.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.details.grammar.notes = value.trim(); updatedValues.details.grammar.notes = value.trim();
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get alphabeticalOrder () { get alphabeticalOrder () {
return store.get('Lexiconga').alphabeticalOrder return this.storedData.alphabeticalOrder
|| defaultDictionary.alphabeticalOrder; || defaultDictionary.alphabeticalOrder;
} }
set alphabeticalOrder (array) { set alphabeticalOrder (array) {
assert(Array.isArray(array), 'Alphabetical Order must be passed as an array'); assert(Array.isArray(array), 'Alphabetical Order must be passed as an array');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.alphabeticalOrder = array updatedValues.alphabeticalOrder = array
.filter((value) => { return value !== '' }) .filter((value) => { return value !== '' })
.map((value) => { return value.trim() }); .map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get settings () { get settings () {
return store.get('Lexiconga').settings return this.storedData.settings
|| defaultDictionary.settings; || defaultDictionary.settings;
} }
get allowDuplicates () { get allowDuplicates () {
return store.get('Lexiconga').settings.allowDuplicates return this.storedData.settings.allowDuplicates
|| defaultDictionary.settings.allowDuplicates; || defaultDictionary.settings.allowDuplicates;
} }
set allowDuplicates (value) { set allowDuplicates (value) {
assert(typeof value === 'boolean', 'allowDuplicates must be passed as a boolean.'); assert(typeof value === 'boolean', 'allowDuplicates must be passed as a boolean.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.settings.allowDuplicates = value; updatedValues.settings.allowDuplicates = value;
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get caseSensitive () { get caseSensitive () {
return store.get('Lexiconga').settings.caseSensitive return this.storedData.settings.caseSensitive
|| defaultDictionary.settings.caseSensitive; || defaultDictionary.settings.caseSensitive;
} }
set caseSensitive (value) { set caseSensitive (value) {
assert(typeof value === 'boolean', 'caseSensitive must be passed as a boolean.'); assert(typeof value === 'boolean', 'caseSensitive must be passed as a boolean.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.settings.caseSensitive = value; updatedValues.settings.caseSensitive = value;
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get sortByDefinition () { get sortByDefinition () {
return store.get('Lexiconga').settings.sortByDefinition return this.storedData.settings.sortByDefinition
|| defaultDictionary.settings.sortByDefinition; || defaultDictionary.settings.sortByDefinition;
} }
set sortByDefinition (value) { set sortByDefinition (value) {
assert(typeof value === 'boolean', 'sortByDefinition must be passed as a boolean.'); assert(typeof value === 'boolean', 'sortByDefinition must be passed as a boolean.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.settings.sortByDefinition = value; updatedValues.settings.sortByDefinition = value;
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get isComplete () { get isComplete () {
return store.get('Lexiconga').settings.isComplete return this.storedData.settings.isComplete
|| defaultDictionary.settings.isComplete; || defaultDictionary.settings.isComplete;
} }
set isComplete (value) { set isComplete (value) {
assert(typeof value === 'boolean', 'isComplete must be passed as a boolean.'); assert(typeof value === 'boolean', 'isComplete must be passed as a boolean.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.settings.isComplete = value; updatedValues.settings.isComplete = value;
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get isPublic () { get isPublic () {
return store.get('Lexiconga').settings.isPublic return this.storedData.settings.isPublic
|| defaultDictionary.settings.isPublic; || defaultDictionary.settings.isPublic;
} }
set isPublic (value) { set isPublic (value) {
assert(typeof value === 'boolean', 'isPublic must be passed as a boolean.'); assert(typeof value === 'boolean', 'isPublic must be passed as a boolean.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.settings.isPublic = value; updatedValues.settings.isPublic = value;
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get lastUpdated () { get lastUpdated () {
return store.get('Lexiconga').lastUpdated return this.storedData.lastUpdated
|| defaultDictionary.lastUpdated; || defaultDictionary.lastUpdated;
} }
set lastUpdated (value) { set lastUpdated (value) {
assert(typeof value === 'number', 'lastUpdated must be passed as a number.'); assert(typeof value === 'number', 'lastUpdated must be passed as a number.');
const updatedValues = store.get('Lexiconga'); const updatedValues = this.storedData;
updatedValues.lastUpdated = value; updatedValues.lastUpdated = value;
return store.set('Lexiconga', updatedValues); this.storedData = updatedValues;
} }
get wordsPromise () { get wordsPromise () {