« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static
diff options
context:
space:
mode:
Diffstat (limited to 'src/static')
-rw-r--r--src/static/js/search-worker.js32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/static/js/search-worker.js b/src/static/js/search-worker.js
index 7932655b..24412b22 100644
--- a/src/static/js/search-worker.js
+++ b/src/static/js/search-worker.js
@@ -4,28 +4,34 @@ import {withEntries} from '../shared-util/sugar.js';
 import FlexSearch from '../lib/flexsearch/flexsearch.bundle.module.min.js';
 
 let status = null;
+let indexes = null;
+let searchData = null;
 
 onmessage = handleWindowMessage;
-
 postStatus('alive');
 
-const indexes =
-  makeSearchIndexes(FlexSearch);
+main().then(
+  () => {
+    postStatus('ready');
+  });
+
+async function main() {
+  indexes =
+    makeSearchIndexes(FlexSearch);
 
-const searchData =
-  await fetch('/search-data/index.json')
-    .then(resp => resp.json());
+  searchData =
+    await fetch('/search-data/index.json')
+      .then(resp => resp.json());
 
-// If this fails, it's because an outdated index was cached.
-// TODO: If this fails, try again once with a cache busting url.
-for (const [indexName, indexData] of Object.entries(searchData)) {
-  for (const [key, value] of Object.entries(indexData)) {
-    indexes[indexName].import(key, value);
+  // If this fails, it's because an outdated index was cached.
+  // TODO: If this fails, try again once with a cache busting url.
+  for (const [indexName, indexData] of Object.entries(searchData)) {
+    for (const [key, value] of Object.entries(indexData)) {
+      indexes[indexName].import(key, value);
+    }
   }
 }
 
-postStatus('ready');
-
 function handleWindowMessage(message) {
   switch (message.data.kind) {
     case 'action':