feat(): Add custom code for events

This commit is contained in:
Depickere Sven 2023-04-25 15:49:20 +01:00
parent d5e5559c49
commit 8c7771e610

View File

@ -72,6 +72,9 @@ export class AppStore {
// update position statically based on hash (in case of SSR)
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
// Listen for external event to update
window.addEventListener('redocUpdatePosition', this.updateOnEvent);
// override the openApi standard to version 3.1.0
// TODO remove when fully supporting open API 3.1.0
spec.openapi = '3.1.0';
@ -98,6 +101,7 @@ export class AppStore {
dispose() {
this.scroll.dispose();
this.menu.dispose();
window.removeEventListener('redocUpdatePosition', this.updateOnEvent);
if (this.search) {
this.search.dispose();
}
@ -125,6 +129,10 @@ export class AppStore {
};
}
private updateOnEvent(): void {
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
}
private updateMarkOnMenu(idx: number) {
const start = Math.max(0, idx);
const end = Math.min(this.menu.flatItems.length, start + 5);