redoc/src/services/SearchStore.ts

38 lines
817 B
TypeScript
Raw Normal View History

2018-03-05 18:58:19 +03:00
import { IMenuItem } from './MenuStore';
2018-02-22 19:48:50 +03:00
import { OperationModel } from './models';
2018-02-08 19:41:02 +03:00
import worker from './SearchWorker.worker';
export class SearchStore {
searchWorker = new worker();
2018-02-22 19:48:50 +03:00
indexItems(groups: Array<IMenuItem | OperationModel>) {
2018-03-06 14:10:08 +03:00
const recurse = groups => {
groups.forEach(group => {
if (group.type !== 'group') {
this.add(group.name, group.description || '', group.id);
}
recurse(group.items);
});
};
recurse(groups);
this.searchWorker.done();
2018-02-08 19:41:02 +03:00
}
add(title: string, body: string, ref: string) {
this.searchWorker.add(title, body, ref);
}
search(q: string) {
return this.searchWorker.search(q);
}
2018-03-06 14:10:08 +03:00
async toJS() {
return this.searchWorker.toJS();
}
load(state: any) {
this.searchWorker.load(state);
}
2018-02-08 19:41:02 +03:00
}