Skip to content

Commit

Permalink
attempt to fix SonarCloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya committed May 3, 2023
1 parent fda5d08 commit a4e1aef
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
6 changes: 2 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function configureMonacoEnvironment() {
};
}

async function bootstrap() {
(async () => {
configureMonacoEnvironment();
const services = await createServices();

Expand All @@ -49,6 +49,4 @@ async function bootstrap() {
</ServicesProvider>
</StrictMode>
);
}

bootstrap();
})();
17 changes: 9 additions & 8 deletions src/services/navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import type React from 'react';

export class NavigationService extends AbstractService {
override afterAppInit() {
try {
this.scrollToHash();
window.dispatchEvent(new HashChangeEvent('hashchange'));
} catch (err: any) {
console.error(err);
}
this.scrollToHash()
.then(() => {
window.dispatchEvent(new HashChangeEvent('hashchange'));
})
.catch((err) => {
console.log(err);
});
}

getUrlParameters() {
Expand All @@ -30,10 +31,10 @@ export class NavigationService extends AbstractService {
try {
const range = this.svcs.parserSvc.getRangeForJsonPath('asyncapi', jsonPointer);
if (range) {
this.scrollToEditorLine(range.start.line + 1);
await this.scrollToEditorLine(range.start.line + 1);
}

this.scrollToHash(hash);
await this.scrollToHash(hash);
this.emitHashChangeEvent(hash);
} catch (e) {
console.error(e);
Expand Down
20 changes: 10 additions & 10 deletions src/services/parser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class ParserService extends AbstractService {
});

this.subscribeToFiles();
this.subscribeToSettings();
this.parseSavedDocuments();
await this.subscribeToSettings();
await this.parseSavedDocuments();
}

async parse(uri: string, spec: string, options: ParseOptions = {}): Promise<void> {
Expand Down Expand Up @@ -137,26 +137,26 @@ export class ParserService extends AbstractService {
}

private subscribeToFiles() {
filesState.subscribe((state, prevState) => {
filesState.subscribe(async (state, prevState) => {
const newFiles = state.files;
const oldFiles = prevState.files;

Object.entries(newFiles).forEach(([uri, file]) => {
Object.entries(newFiles).forEach(([uri, file]) => async () => {
const oldFile = oldFiles[String(uri)];
if (file === oldFile) return;
this.parse(uri, file.content, { source: file.source });
await this.parse(uri, file.content, { source: file.source });
});
});
}

private subscribeToSettings() {
settingsState.subscribe((state, prevState) => {
private async subscribeToSettings() {
settingsState.subscribe((state, prevState) => async () => {
if (isDeepEqual(state.governance, prevState.governance)) return;

const { files } = filesState.getState();
Object.entries(files).forEach(([uri, file]) => {
this.parse(uri, file.content);
});
for (const [uri, file] of Object.entries(files)) {
await this.parse(uri, file.content);
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const AsyncAPIStudio: React.FunctionComponent<AsyncAPIStudioProps> = () =
const services = useServices();

useEffect(() => {
setTimeout(() => {
afterAppInit(services);
setTimeout(async () => {
await afterAppInit(services);
}, 250);
}, []);

Expand Down

0 comments on commit a4e1aef

Please sign in to comment.