From 025b1f398b7e498a0a61ebee095498caccb46819 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:38:08 -0400 Subject: Simplify access to details fields in createTermEntry --- ext/mixed/js/display-generator.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index b2d34cfc..19f6a56e 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -44,13 +44,15 @@ class DisplayGenerator { const debugInfoContainer = node.querySelector('.debug-info'); const bodyContainer = node.querySelector('.term-entry-body'); + const {termTags, expressions, definitions} = details; + const pitches = this._getPitchInfos(details); const pitchCount = pitches.reduce((i, v) => i + v[1].length, 0); - const expressionMulti = Array.isArray(details.expressions); - const definitionMulti = Array.isArray(details.definitions); - const expressionCount = expressionMulti ? details.expressions.length : 1; - const definitionCount = definitionMulti ? details.definitions.length : 1; + const expressionMulti = Array.isArray(expressions); + const definitionMulti = Array.isArray(definitions); + const expressionCount = expressionMulti ? expressions.length : 1; + const definitionCount = definitionMulti ? definitions.length : 1; const uniqueExpressionCount = Array.isArray(details.expression) ? new Set(details.expression).size : 1; node.dataset.expressionMulti = `${expressionMulti}`; @@ -66,15 +68,11 @@ class DisplayGenerator { (pitches.length > 0 ? 1 : 0) }`; - const termTags = details.termTags; - let expressions = details.expressions; - expressions = Array.isArray(expressions) ? expressions : [details]; - - this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, termTags); + this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressionMulti ? expressions : [details], termTags); this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons); this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); - this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? details.definitions : [details]); + this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? definitions : [details]); if (debugInfoContainer !== null) { debugInfoContainer.textContent = JSON.stringify(details, null, 4); -- cgit v1.2.3