Update _appendMultiple to not use a fallback
This commit is contained in:
parent
f9bdf2c66f
commit
6788bb31d2
@ -68,13 +68,13 @@ class DisplayGenerator {
|
|||||||
|
|
||||||
const termTags = details.termTags;
|
const termTags = details.termTags;
|
||||||
let expressions = details.expressions;
|
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(reasonsContainer, this._createTermReason.bind(this), details.reasons);
|
||||||
this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies);
|
this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies);
|
||||||
this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches);
|
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) {
|
if (debugInfoContainer !== null) {
|
||||||
debugInfoContainer.textContent = JSON.stringify(details, null, 4);
|
debugInfoContainer.textContent = JSON.stringify(details, null, 4);
|
||||||
@ -447,23 +447,24 @@ class DisplayGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_appendMultiple(container, createItem, detailsIterable, fallback=[]) {
|
_isIterable(value) {
|
||||||
if (container === null) { return 0; }
|
return (
|
||||||
|
value !== null &&
|
||||||
const multi = (
|
typeof value === 'object' &&
|
||||||
detailsIterable !== null &&
|
typeof value[Symbol.iterator] !== 'undefined'
|
||||||
typeof detailsIterable === 'object' &&
|
|
||||||
typeof detailsIterable[Symbol.iterator] !== 'undefined'
|
|
||||||
);
|
);
|
||||||
if (!multi) { detailsIterable = fallback; }
|
}
|
||||||
|
|
||||||
|
_appendMultiple(container, createItem, detailsIterable) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
if (container !== null && this._isIterable(detailsIterable)) {
|
||||||
for (const details of detailsIterable) {
|
for (const details of detailsIterable) {
|
||||||
const item = createItem(details);
|
const item = createItem(details);
|
||||||
if (item === null) { continue; }
|
if (item === null) { continue; }
|
||||||
container.appendChild(item);
|
container.appendChild(item);
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
container.dataset.count = `${count}`;
|
container.dataset.count = `${count}`;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user