aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/display-generator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-25 00:14:27 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-28 10:25:57 -0400
commit168bd72d0a5289646c78c57f6f36fe2aa1a194eb (patch)
treedb67e8642f4c45a8b7a6599504c2f5257ab7dd63 /ext/mixed/js/display-generator.js
parent93f7278586f7b943ae49c00cd14559a2f4b99561 (diff)
Update _appendMultiple to support general iterables
Diffstat (limited to 'ext/mixed/js/display-generator.js')
-rw-r--r--ext/mixed/js/display-generator.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js
index 41f7315a..d88b8648 100644
--- a/ext/mixed/js/display-generator.js
+++ b/ext/mixed/js/display-generator.js
@@ -301,22 +301,28 @@ class DisplayGenerator {
}
}
- static _appendMultiple(container, createItem, detailsArray, fallback=[]) {
+ static _appendMultiple(container, createItem, detailsIterable, fallback=[]) {
if (container === null) { return 0; }
- const isArray = Array.isArray(detailsArray);
- if (!isArray) { detailsArray = fallback; }
+ const multi = (
+ detailsIterable !== null &&
+ typeof detailsIterable === 'object' &&
+ typeof detailsIterable[Symbol.iterator] !== 'undefined'
+ );
+ if (!multi) { detailsIterable = fallback; }
- container.dataset.multi = `${isArray}`;
- container.dataset.count = `${detailsArray.length}`;
-
- for (const details of detailsArray) {
+ let count = 0;
+ for (const details of detailsIterable) {
const item = createItem(details);
if (item === null) { continue; }
container.appendChild(item);
+ ++count;
}
- return detailsArray.length;
+ container.dataset.multi = `${multi}`;
+ container.dataset.count = `${count}`;
+
+ return count;
}
static _appendFurigana(container, segments, addText) {