mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +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) {
|
load(state: any) {
|
||||||
this.searchWorker.load(state);
|
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;
|
toJS = toJS;
|
||||||
load = load;
|
load = load;
|
||||||
dispose = dispose;
|
dispose = dispose;
|
||||||
|
fromExternalJS = fromExternalJS;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchDocument {
|
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) {
|
export async function load(state: any) {
|
||||||
store = state.store;
|
store = state.store;
|
||||||
resolveIndex(lunr.Index.load(state.index));
|
resolveIndex(lunr.Index.load(state.index));
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
"es2015",
|
"es2015",
|
||||||
"es2016",
|
"es2016",
|
||||||
"es2017",
|
"es2017",
|
||||||
"dom"
|
"dom",
|
||||||
|
"WebWorker.ImportScripts"
|
||||||
],
|
],
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"types": [
|
"types": [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user