diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-04-09 22:16:55 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-04-09 22:40:25 -0400 |
commit | 6788bb31d241e1b77a6630df3d617de4a9470f26 (patch) | |
tree | f470b8d6b99cd0feb55941c77fa7ba0dfbbb8e49 /ext/mixed/js/display-generator.js | |
parent | f9bdf2c66f5eca0ecb1c21f231492be47e40e690 (diff) |
Update _appendMultiple to not use a fallback
Diffstat (limited to 'ext/mixed/js/display-generator.js')
-rw-r--r-- | ext/mixed/js/display-generator.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index 951f16ec..5c4b330d 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -68,13 +68,13 @@ class DisplayGenerator { const termTags = details.termTags; let expressions = details.expressions; - expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : null; + expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : [[details, termTags]]; - this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, [[details, termTags]]); + this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions); 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), details.definitions, [details]); + this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? details.definitions : [details]); if (debugInfoContainer !== null) { debugInfoContainer.textContent = JSON.stringify(details, null, 4); @@ -447,22 +447,23 @@ class DisplayGenerator { } } - _appendMultiple(container, createItem, detailsIterable, fallback=[]) { - if (container === null) { return 0; } - - const multi = ( - detailsIterable !== null && - typeof detailsIterable === 'object' && - typeof detailsIterable[Symbol.iterator] !== 'undefined' + _isIterable(value) { + return ( + value !== null && + typeof value === 'object' && + typeof value[Symbol.iterator] !== 'undefined' ); - if (!multi) { detailsIterable = fallback; } + } + _appendMultiple(container, createItem, detailsIterable) { let count = 0; - for (const details of detailsIterable) { - const item = createItem(details); - if (item === null) { continue; } - container.appendChild(item); - ++count; + if (container !== null && this._isIterable(detailsIterable)) { + for (const details of detailsIterable) { + const item = createItem(details); + if (item === null) { continue; } + container.appendChild(item); + ++count; + } } container.dataset.count = `${count}`; |