summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-11-05 16:44:29 -0700
committerAlex Yatskov <alex@foosoft.net>2016-11-05 16:44:29 -0700
commitfd2820bc1af1f2a4dac477f1d2963a3b913fdb32 (patch)
tree61dafb0932bfab65682dbd28c3296a2ab5979124 /ext/bg/js/util.js
parent909218c82b42812feebfac4459939176e68ba621 (diff)
WIP
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 4e0cc671..888bcb33 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -116,3 +116,27 @@ function applyTagMeta(tag, meta) {
function splitField(field) {
return field.length === 0 ? [] : field.split(' ');
}
+
+function importJsonDb(indexUrl, entitiesLoaded, entriesLoaded) {
+ const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/'));
+ return loadJson(indexUrl).then(index => {
+ if (entitiesLoaded !== null) {
+ return entitiesLoaded(index.entities, index.banks).then(() => index);
+ }
+
+ return index;
+ }).then(index => {
+ const loaders = [];
+ for (let i = 1; i <= index.banks; ++i) {
+ const bankUrl = `${indexDir}/bank_${i}.json`;
+ loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(entries, index.banks, i)));
+ }
+
+ let chain = Promise.resolve();
+ for (const loader of loaders) {
+ chain = chain.then(loader);
+ }
+
+ return chain;
+ });
+}