Merge pull request #5 from sofico-global/fiva/winEventScroll

feat: add listening for redocUpdatePosition event on window to update…
This commit is contained in:
Filip Van Ham 2023-04-26 11:48:09 +02:00 committed by GitHub
commit 21279e1d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "redoc", "name": "redoc",
"version": "2.0.0-0.2.0", "version": "2.0.0-0.2.1",
"description": "ReDoc", "description": "ReDoc",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -58,6 +58,8 @@ export class AppStore {
private scroll: ScrollService; private scroll: ScrollService;
private disposer: Lambda | null = null; private disposer: Lambda | null = null;
private readonly listener: EventListenerOrEventListenerObject = this.updateOnEvent.bind(this);
constructor( constructor(
spec: OpenAPISpec, spec: OpenAPISpec,
specUrl?: string, specUrl?: string,
@ -73,7 +75,7 @@ export class AppStore {
MenuStore.updateOnHistory(this.history.currentId, this.scroll); MenuStore.updateOnHistory(this.history.currentId, this.scroll);
// Listen for external event to update // Listen for external event to update
window.addEventListener('redocUpdatePosition', this.updateOnEvent); window.addEventListener('redocUpdatePosition', this.listener);
// override the openApi standard to version 3.1.0 // override the openApi standard to version 3.1.0
// TODO remove when fully supporting open API 3.1.0 // TODO remove when fully supporting open API 3.1.0
@ -101,7 +103,7 @@ export class AppStore {
dispose() { dispose() {
this.scroll.dispose(); this.scroll.dispose();
this.menu.dispose(); this.menu.dispose();
window.removeEventListener('redocUpdatePosition', this.updateOnEvent); window.removeEventListener('redocUpdatePosition', this.listener);
if (this.search) { if (this.search) {
this.search.dispose(); this.search.dispose();
} }
@ -129,10 +131,6 @@ export class AppStore {
}; };
} }
private updateOnEvent(): void {
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
}
private updateMarkOnMenu(idx: number) { private updateMarkOnMenu(idx: number) {
const start = Math.max(0, idx); const start = Math.max(0, idx);
const end = Math.min(this.menu.flatItems.length, start + 5); const end = Math.min(this.menu.flatItems.length, start + 5);
@ -157,6 +155,10 @@ export class AppStore {
this.marker.addOnly(elements); this.marker.addOnly(elements);
this.marker.mark(); this.marker.mark();
} }
private updateOnEvent(): void {
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
}
} }
const DEFAULT_OPTIONS: RedocRawOptions = { const DEFAULT_OPTIONS: RedocRawOptions = {