Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TS integration cv-frontend-vue\src\simulator\src\data.js #477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions src/simulator/src/data.js

This file was deleted.

82 changes: 82 additions & 0 deletions src/simulator/src/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { fullView } from './ux';
import { createSubCircuitPrompt } from './subcircuit';
import save from './data/save';
import load from './data/load';
import createSaveAsImgPrompt from './data/saveImage';
import {
clearProject,
newProject,
saveOffline,
openOffline,
recoverProject,
} from './data/project';
import { createNewCircuitScope } from './circuit';
import { createCombinationalAnalysisPrompt } from './combinationalAnalysis';
import { colorThemes } from './themer/themer';
import { showTourGuide } from './tutorials';
import { createVerilogCircuit } from './Verilog2CV';
import { generateVerilog } from './verilog';
import { bitConverterDialog } from './utils';
import { keyBinder } from '#/components/DialogBox/CustomShortcut.vue';
import { ExportProject } from '#/components/DialogBox/ExportProject.vue';
import { ImportProject } from '#/components/DialogBox/ImportProject.vue';

interface LogixFunction {
save: typeof save;
load: typeof load;
createSaveAsImgPrompt: typeof createSaveAsImgPrompt;
clearProject: typeof clearProject;
newProject: typeof newProject;
saveOffline: typeof saveOffline;
createOpenLocalPrompt: typeof openOffline;
recoverProject: typeof recoverProject;
createSubCircuitPrompt: typeof createSubCircuitPrompt;
createCombinationalAnalysisPrompt: typeof createCombinationalAnalysisPrompt;
fullViewOption: typeof fullView;
colorThemes: typeof colorThemes;
showTourGuide: () => void;
newVerilogModule: typeof createVerilogCircuit;
generateVerilog: typeof generateVerilog;
bitconverter: typeof bitConverterDialog;
createNewCircuitScope: () => void;
customShortcut: typeof keyBinder;
ExportProject: typeof ExportProject;
ImportProject: typeof ImportProject;
}

const logixFunction: LogixFunction = {
save,
load,
createSaveAsImgPrompt,
clearProject,
newProject,
saveOffline,
createOpenLocalPrompt: openOffline,
recoverProject,
createSubCircuitPrompt,
createCombinationalAnalysisPrompt,
fullViewOption: fullView,
colorThemes,
showTourGuide: showTourGuideHelper,
newVerilogModule: createVerilogCircuit,
generateVerilog,
bitconverter: bitConverterDialog,
createNewCircuitScope: createNewCircuit,
customShortcut: keyBinder,
ExportProject,
ImportProject,
};

export default logixFunction;

// Hack to restart tour guide
function showTourGuideHelper(): void {
setTimeout(() => {
showTourGuide();
}, 100);
}
Comment on lines +72 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace setTimeout hack with proper event handling.

The comment and setTimeout suggest a timing issue. This could be improved by:

  1. Using proper event handling to ensure the tour guide starts at the right time
  2. Adding error handling for robustness
-// Hack to restart tour guide
-function showTourGuideHelper(): void {
-    setTimeout(() => {
-        showTourGuide();
-    }, 100);
-}
+/**
+ * Starts the tour guide when the application is ready.
+ * @throws Error if the tour guide fails to start
+ */
+function showTourGuideHelper(): void {
+    try {
+        // Replace with proper event-based initialization
+        showTourGuide();
+    } catch (error) {
+        console.error('Failed to start tour guide:', error);
+        throw error;
+    }
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Hack to restart tour guide
function showTourGuideHelper(): void {
setTimeout(() => {
showTourGuide();
}, 100);
}
/**
* Starts the tour guide when the application is ready.
* @throws Error if the tour guide fails to start
*/
function showTourGuideHelper(): void {
try {
// Replace with proper event-based initialization
showTourGuide();
} catch (error) {
console.error('Failed to start tour guide:', error);
throw error;
}
}


// Hack to call createNewCircuitScope with keyboard shortcut
function createNewCircuit(): void {
createNewCircuitScope();
}