Improve word render speed

This commit is contained in:
Robbie Antenesse 2019-05-07 10:02:40 -06:00
parent d3c5633821
commit d5edcaf6a5
1 changed files with 18 additions and 14 deletions

View File

@ -28,20 +28,24 @@ export function getSearchFilters() {
export function getMatchingSearchWords() { export function getMatchingSearchWords() {
const searchTerm = getSearchTerm(); const searchTerm = getSearchTerm();
const filters = getSearchFilters(); const filters = getSearchFilters();
const matchingWords = window.currentDictionary.words.slice().filter(word => { if (searchTerm !== '' || !filters.allPartsOfSpeechChecked) {
if (!filters.allPartsOfSpeechChecked) { const matchingWords = window.currentDictionary.words.slice().filter(word => {
const partOfSpeech = word.partOfSpeech === '' ? 'Unclassified' : word.partOfSpeech; if (!filters.allPartsOfSpeechChecked) {
console.log('partOfSpeech', partOfSpeech); const partOfSpeech = word.partOfSpeech === '' ? 'Unclassified' : word.partOfSpeech;
return filters.partsOfSpeech.hasOwnProperty(partOfSpeech) && filters.partsOfSpeech[partOfSpeech]; console.log('partOfSpeech', partOfSpeech);
} return filters.partsOfSpeech.hasOwnProperty(partOfSpeech) && filters.partsOfSpeech[partOfSpeech];
return true; }
}).filter(word => { return true;
const isInName = filters.name && new RegExp(searchTerm, 'g').test(word.name); }).filter(word => {
const isInDefinition = filters.definition && new RegExp(searchTerm, 'g').test(word.simpleDefinition); const isInName = filters.name && new RegExp(searchTerm, 'g').test(word.name);
const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(word.longDefinition); const isInDefinition = filters.definition && new RegExp(searchTerm, 'g').test(word.simpleDefinition);
return searchTerm === '' || isInName || isInDefinition || isInDetails; const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(word.longDefinition);
}); return searchTerm === '' || isInName || isInDefinition || isInDetails;
return matchingWords; });
return matchingWords;
}
return window.currentDictionary.words
} }
export function highlightSearchTerm(word) { export function highlightSearchTerm(word) {