feat: load external search index

This commit is contained in:
Roman Hotsiy 2020-09-24 14:03:16 +03:00
parent 9730c4ee1c
commit 346b10f173
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
3 changed files with 22 additions and 1 deletions

View File

@ -56,4 +56,10 @@ export class SearchStore<T> {
load(state: any) {
this.searchWorker.load(state);
}
fromExternalJS(path?: string, exportName?: string) {
if (path && exportName) {
this.searchWorker.fromExternalJS(path, exportName)
}
}
}

View File

@ -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));

View File

@ -17,7 +17,8 @@
"es2015",
"es2016",
"es2017",
"dom"
"dom",
"WebWorker.ImportScripts"
],
"jsx": "react",
"types": [