refactor(): Make historyService work with config

This commit is contained in:
Depickere Sven 2023-02-21 15:01:12 +01:00
parent de146726dd
commit 9bf6a53e84
3 changed files with 8 additions and 14 deletions

View File

@ -2,7 +2,7 @@ import { Lambda, observe } from 'mobx';
import type { OpenAPISpec } from '../types';
import { loadAndBundleSpec } from '../utils/loadAndBundleSpec';
import { history } from './HistoryService';
import { HistoryService } from './HistoryService';
import { MarkerService } from './MarkerService';
import { MenuStore } from './MenuStore';
import { SpecStore } from './models';
@ -53,6 +53,7 @@ export class AppStore {
options: RedocNormalizedOptions;
search?: SearchStore<string>;
marker = new MarkerService();
history;
private scroll: ScrollService;
private disposer: Lambda | null = null;
@ -65,13 +66,14 @@ export class AppStore {
) {
this.rawOptions = options;
this.options = new RedocNormalizedOptions(options, DEFAULT_OPTIONS);
this.history = new HistoryService(this.options);
this.scroll = new ScrollService(this.options);
// update position statically based on hash (in case of SSR)
MenuStore.updateOnHistory(history.currentId, this.scroll);
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
this.spec = new SpecStore(spec, specUrl, this.options);
this.menu = new MenuStore(this.spec, this.scroll, history);
this.menu = new MenuStore(this.spec, this.scroll, this.history);
if (!this.options.disableSearch) {
this.search = new SearchStore();

View File

@ -94,14 +94,6 @@ export class HistoryService {
}
private getHrefSplitCharacter(): string {
return this.shouldQueryParamNavigationBeUsed() ? '#' : '?redoc';
return this.shouldQueryParamNavigationBeUsed() ? '?redoc' : '#';
}
}
export const history = new HistoryService();
if (module.hot) {
module.hot.dispose(() => {
history.dispose();
});
}

View File

@ -2,7 +2,7 @@ import { action, observable, makeObservable } from 'mobx';
import { querySelector } from '../utils/dom';
import { escapeHTMLAttrChars, flattenByProp, SECURITY_SCHEMES_SECTION_PREFIX } from '../utils';
import { history as historyInst, HistoryService } from './HistoryService';
import { HistoryService } from './HistoryService';
import { GROUP_DEPTH } from './MenuBuilder';
import type { SpecStore } from './models';
@ -21,7 +21,7 @@ export class MenuStore {
* Statically try update scroll position
* Used before hydrating from server-side rendered html to scroll page faster
*/
static updateOnHistory(id: string = historyInst.currentId, scroll: ScrollService) {
static updateOnHistory(id: string, scroll: ScrollService) {
if (!id) {
return;
}