mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
feat: load external search index
This commit is contained in:
parent
9730c4ee1c
commit
346b10f173
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
"es2015",
|
||||
"es2016",
|
||||
"es2017",
|
||||
"dom"
|
||||
"dom",
|
||||
"WebWorker.ImportScripts"
|
||||
],
|
||||
"jsx": "react",
|
||||
"types": [
|
||||
|
|
Loading…
Reference in New Issue
Block a user