diff --git a/src/services/SearchStore.ts b/src/services/SearchStore.ts index 88cd9d31..ebf2ca56 100644 --- a/src/services/SearchStore.ts +++ b/src/services/SearchStore.ts @@ -56,4 +56,10 @@ export class SearchStore { load(state: any) { this.searchWorker.load(state); } + + fromExternalJS(path?: string, exportName?: string) { + if (path && exportName) { + this.searchWorker.fromExternalJS(path, exportName) + } + } } diff --git a/src/services/SearchWorker.worker.ts b/src/services/SearchWorker.worker.ts index c9433d51..451a8445 100644 --- a/src/services/SearchWorker.worker.ts +++ b/src/services/SearchWorker.worker.ts @@ -15,6 +15,7 @@ export default class Worker { toJS = toJS; load = load; dispose = dispose; + fromExternalJS = fromExternalJS; } export interface SearchDocument { @@ -72,6 +73,19 @@ export async function toJS() { }; } +export async function fromExternalJS(path: string, exportName: string) { + try { + importScripts(path); + if (!self[exportName]) { + throw new Error('Broken index file format'); + } + + load(self[exportName]); + } catch (e) { + console.error('Failed to load search index: ' + e.message); + } +} + export async function load(state: any) { store = state.store; resolveIndex(lunr.Index.load(state.index)); diff --git a/tsconfig.json b/tsconfig.json index eff5172a..18a22b36 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,8 @@ "es2015", "es2016", "es2017", - "dom" + "dom", + "WebWorker.ImportScripts" ], "jsx": "react", "types": [