1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-04-16 00:20:14 +02:00

Expand and use default dictionary and Updater

This commit is contained in:
Robbie Antenesse 2017-08-20 14:41:08 -06:00
parent 97170803fa
commit 9b7e797aef
4 changed files with 124 additions and 28 deletions

View file

@ -27,29 +27,8 @@ export const MainDisplay = ({ dictionaryInfo, wordsToDisplay, updateDisplay, upd
specification={ dictionaryInfo.specification }
description={ dictionaryInfo.description }
partsOfSpeech={ dictionaryInfo.partsOfSpeech }
alphabeticalOrder={['b', 'p', 't', 'd', 'a', 'o', 'j', 'e']}
details={{
phonology: {
consonants: ['b', 'p', 'd', 't', 'j'],
vowels: ['a', 'o', 'e'],
blends: ['ae', 'oe', 'tj', 'dy'],
phonotactics: {
onset: ['b', 'p', 'j'],
nucleus: ['a', 'o', 'e'],
coda: ['any'],
exceptions: 'There are no exceptions',
},
},
grammar: {
content: 'The rules of the language are simple: just follow them!'
},
custom: [
{
name: 'Test Tab',
content: 'This is a test tab to test how custom tabs work!',
}
],
}}
details={ dictionaryInfo.details }
alphabeticalOrder={ dictionaryInfo.alphabeticalOrder }
/>
<WordsList

View file

@ -24,6 +24,9 @@ class App extends Component {
specification: dictionary.specification,
description: dictionary.description,
partsOfSpeech: dictionary.partsOfSpeech,
details: dictionary.details,
alphabeticalOrder: dictionary.alphabeticalOrder,
displayedWords: [],
searchConfig: null,
}
@ -32,15 +35,23 @@ class App extends Component {
}
get dictionaryInfo () {
const { name, specification, description, partsOfSpeech } = this.state;
const info = {
const {
name,
specification,
description,
partsOfSpeech,
};
details,
alphabeticalOrder,
} = this.state;
return info;
return {
name,
specification,
description,
partsOfSpeech,
details,
alphabeticalOrder,
};
}
updatePartsOfSpeech () {

View file

@ -8,10 +8,38 @@ const defaultDictionary = {
specification: 'Dictionary',
description: 'A new dictionary.',
partsOfSpeech: ['Noun', 'Adjective', 'Verb'],
}
details: {
phonology: {
consonants: ['b', 'p', 'ɱ', 'ʃ', 'ʁ'],
vowels: ['a', 'o', 'e'],
blends: ['ae', 'oe', 'ɱʃ', 'pʁ'],
phonotactics: {
onset: ['none'],
nucleus: ['vowels'],
coda: ['any'],
exceptions: `You can enter exceptions to your phonotactics here using [Markdown](MARKDOWN_LINK)!`,
},
},
orthography: {
notes: `You can enter notes on orthography here using [Markdown](MARKDOWN_LINK)!`
},
grammar: {
content: `You can enter grammar rules about your language here using [Markdown](MARKDOWN_LINK)!`,
},
custom: [
{
name: 'Example Tab',
content: `This is an _example_ tab to show how **tabs** work with [Markdown](MARKDOWN_LINK)!`,
}
],
},
alphabeticalOrder: ['b', 'p', 't', 'd', 'a', 'o', 'j', 'e'],
};
class DictionaryData {
constructor () {
this.default = defaultDictionary;
if (['emptydb', 'donotsave'].includes(process.env.NODE_ENV)) {
store.remove('Lexiconga');
}
@ -80,6 +108,67 @@ class DictionaryData {
return store.set('Lexiconga', updatedValues);
}
get details () {
return store.get('Lexiconga').details
|| defaultDictionary.details;
}
get consonants () {
return store.get('Lexiconga').details.phonology.consonants
|| defaultDictionary.details.phonology.consonants;
}
set consonants (array) {
assert(Array.isArray(array), 'Consonants must be passed as an array');
const updatedValues = store.get('Lexiconga');
updatedValues.details.phonology.consonants = array
.filter((value) => { return value !== '' })
.map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues);
}
get vowels () {
return store.get('Lexiconga').details.phonology.vowels
|| defaultDictionary.details.phonology.vowels;
}
set vowels (array) {
assert(Array.isArray(array), 'Vowels must be passed as an array');
const updatedValues = store.get('Lexiconga');
updatedValues.details.phonology.vowels = array
.filter((value) => { return value !== '' })
.map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues);
}
get blends () {
return store.get('Lexiconga').details.phonology.blends
|| defaultDictionary.details.phonology.blends;
}
set blends (array) {
assert(Array.isArray(array), 'Blends must be passed as an array');
const updatedValues = store.get('Lexiconga');
updatedValues.details.phonology.blends = array
.filter((value) => { return value !== '' })
.map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues);
}
get alphabeticalOrder () {
return store.get('Lexiconga').alphabeticalOrder
|| defaultDictionary.alphabeticalOrder;
}
set alphabeticalOrder (array) {
assert(Array.isArray(array), 'Parts of Speech must be passed as an array');
const updatedValues = store.get('Lexiconga');
updatedValues.alphabeticalOrder = array
.filter((value) => { return value !== '' })
.map((value) => { return value.trim() });
return store.set('Lexiconga', updatedValues);
}
get wordsPromise () {
return wordDb.words.toArray();
}

View file

@ -46,6 +46,23 @@ export class Updater {
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;
}
console.log(updatedDetails);
if (updatedDetails.isEmpty()) {
reject('No dictionary details have changed.');
} else {