diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-04-18 18:11:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-18 18:11:09 -0400 |
commit | 03dd1dc6ff808390fed7e770822a961c4db3fb2a (patch) | |
tree | eff73ea2d8869a82bd469084fd529b42283ad0eb /ext/js/data/anki-note-data-creator.js | |
parent | f9774b4ce985b9920cee8afec0f756e5e1bfc9fa (diff) |
Remove redundant dictionary entry sequence (#1618)
* Remove sequence/sequenceDictionary from dictionary entry objects
* Expose isPrimary on definitions
* Update sequence
* Update test data
Diffstat (limited to 'ext/js/data/anki-note-data-creator.js')
-rw-r--r-- | ext/js/data/anki-note-data-creator.js | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/ext/js/data/anki-note-data-creator.js b/ext/js/data/anki-note-data-creator.js index 1cd5aaf4..f4d6ab49 100644 --- a/ext/js/data/anki-note-data-creator.js +++ b/ext/js/data/anki-note-data-creator.js @@ -265,7 +265,7 @@ class AnkiNoteDataCreator { case 'merge': type = 'termMerged'; break; } - const {id, inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, sequence} = dictionaryEntry; + const {id, inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount} = dictionaryEntry; const { screenshotFileName=null, @@ -288,6 +288,7 @@ class AnkiNoteDataCreator { const glossary = this.createCachedValue(this._getTermGlossaryArray.bind(this, dictionaryEntry, type)); const cloze = this.createCachedValue(this._getCloze.bind(this, dictionaryEntry, context)); const furiganaSegments = this.createCachedValue(this._getTermFuriganaSegments.bind(this, dictionaryEntry, type)); + const sequence = this.createCachedValue(this._getTermDictionaryEntrySequence.bind(this, dictionaryEntry)); return { type, @@ -298,7 +299,7 @@ class AnkiNoteDataCreator { reasons: inflections, score, isPrimary: (type === 'term' ? dictionaryEntry.isPrimary : void 0), - sequence, + get sequence() { return self.getCachedValue(sequence); }, get dictionary() { return self.getCachedValue(dictionaryNames)[0]; }, dictionaryOrder: { index: dictionaryIndex, @@ -601,4 +602,21 @@ class AnkiNoteDataCreator { } return result; } + + _getTermDictionaryEntrySequence(dictionaryEntry) { + let hasSequence = false; + let mainSequence = -1; + for (const {sequence, isPrimary} of dictionaryEntry.definitions) { + if (!isPrimary) { continue; } + if (!hasSequence) { + mainSequence = sequence; + hasSequence = true; + if (mainSequence === -1) { break; } + } else if (mainSequence !== sequence) { + mainSequence = -1; + break; + } + } + return mainSequence; + } } |