Skip to content

Commit

Permalink
Optimized type structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kerwin612 committed Mar 11, 2022
1 parent 3456ad3 commit 0365e40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ export interface HistoryEntry {
url?: string;
}

export interface DocConfig {
[key: string]: {
code: string;
config?: string;
};
}

type Loader = (url: string) => Promise<State>;
10 changes: 4 additions & 6 deletions src/routes/edit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { onMount } from 'svelte';
import mermaid from 'mermaid';
import type monaco from 'monaco-editor';
import type { EditorUpdateEvent, State, Tab } from '$lib/types';
import type { EditorUpdateEvent, State, Tab, DocConfig } from '$lib/types';
import { base } from '$app/paths';
serializedState; // Weird fix for error > serializedState is not defined. Treeshaking?
Expand All @@ -21,7 +21,7 @@
code: 'mermaid',
config: 'json'
};
const docMap = {
const docMap: DocConfig = {
graph: {
code: '/#/flowchart',
config: '/#/flowchart?id=configuration'
Expand Down Expand Up @@ -71,10 +71,8 @@
}
let codeTypeMatch = /([\S]+)[\s\n]/.exec(state.code);
let docKey = codeTypeMatch && codeTypeMatch.length > 1 ? codeTypeMatch[1] : null;
docURL =
((docKey && docMap[docKey]) || {})[selectedMode] ||
((docKey && docMap[docKey]) || {})['code'] ||
'';
let docConfig = (docKey && docMap[docKey]) || {};
docURL = docConfig[selectedMode] || docConfig['code'] || '';
});
const tabSelectHandler = (message: CustomEvent<Tab>) => {
$codeStore.updateEditor = true;
Expand Down

0 comments on commit 0365e40

Please sign in to comment.