Skip to content

Conversation

@s1dhu98
Copy link
Contributor

@s1dhu98 s1dhu98 commented Jan 24, 2026

Description

Convert src/simulator/src/events.js to TypeScript with proper type annotations.

Changes

  • Convert events.js to events.ts with full TypeScript support
  • Add proper type annotations for function parameters and return types
  • Define CopyData interface for better type safety
  • Replace var with const/let for better scoping and block scope
  • Update variable comparisons to use strict equality (=== instead of ==)
  • Maintain all existing functionality and logic

Type Improvements

  • paste(copyData: string): void
  • cut(copyList: any[]): string
  • copy(copyList: any[], cutflag?: boolean): string
  • selectAll(scope?: any): void
  • CopyData interface for JSON data structure

Related to

Closes/relates to #661 (JavaScript to TypeScript conversion in src folder)

Summary by CodeRabbit

  • Refactor
    • Enhanced code quality and type safety in the simulator's event handling system through improved variable management and explicit type definitions for better maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.

- Convert events.js to events.ts with full TypeScript support
- Add proper type annotations for function parameters and return types
- Define CopyData interface for better type safety
- Replace var with const/let for better scoping
- Update variable comparisons to use strict equality (=== instead of ==)
- Maintain all existing functionality and logic

Relates to: CircuitVerse#661 (JavaScript to TypeScript conversion in src folder)
@netlify
Copy link

netlify bot commented Jan 24, 2026

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 4d92008
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/69785ebb4765ac0008de27b5
😎 Deploy Preview https://deploy-preview-858--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 43 (🔴 down 4 from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Walkthrough

The changes in this PR apply TypeScript conversion to the events.ts file. A new CopyData interface is introduced to type clipboard data. Function signatures are updated with parameter and return type annotations for paste, cut, copy, and selectAll. Variable declarations are refactored from var to const/let throughout. Loose equality comparisons (==, !=) are replaced with strict equality (===, !==). Explicit typing is added to function parameters, local variables, and loop variables.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: Convert events.js to TypeScript' clearly and specifically summarizes the main change of converting a single JavaScript file to TypeScript.
Linked Issues check ✅ Passed The PR converts events.js to TypeScript with proper type annotations and a new CopyData interface, aligning with issue #661's objective to add interfaces, data types, and improve type safety while preserving logic.
Out of Scope Changes check ✅ Passed All changes focus on TypeScript conversion: replacing var with const/let, adding type annotations to functions, introducing CopyData interface, and switching to strict equality checks—all aligned with issue #661 requirements and without altering existing logic.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/simulator/src/events.ts`:
- Around line 28-31: The paste function currently checks for the literal string
'undefined' which is incorrect for callers that pass localStorage.getItem(...)
(string|null) or clipboard API strings; update the paste signature to accept
string | null (change export function paste(copyData: string): void to export
function paste(copyData: string | null): void), remove the "undefined" string
comparison, and replace it with a proper null/falsy check such as if (copyData
== null || copyData === '') return; so JSON.parse is only called on real strings
and preserves compatibility with copy() returning an empty string; alternatively
add a brief comment if you intentionally need to preserve a legacy 'undefined'
literal.
🧹 Nitpick comments (3)
src/simulator/src/events.ts (3)

18-22: CopyData interface is acceptable for incremental migration, but consider future improvements.

The interface uses any[] for scopes and an index signature [key: string]: any, which provides basic type safety while allowing flexibility. This is reasonable for an incremental JS-to-TS conversion.

For future iterations, consider defining a more specific type based on the structure returned by backUp() (from backupCircuit.js), which includes known properties like layout, verilogMetadata, allNodes, testbenchData, id, name, etc.


149-150: Use const instead of let for d since it's not reassigned.

The variable d is only assigned once and never reassigned, so it should be declared with const for consistency with the other immutable variables in this function.

Suggested fix
-    let d = backUp(globalScope)
+    const d = backUp(globalScope)

333-338: Consider adding explicit type annotation for the scope parameter.

The scope parameter uses globalScope as a default value but lacks an explicit type annotation. TypeScript will infer the type from globalScope, but an explicit type would improve readability and maintainability.

Based on the learnings, globalScope is a global variable that should be typed by extending the Window interface. If a Scope type is available (imported from ./circuit), consider using it here.

Suggested improvement
-export function selectAll(scope = globalScope): void {
+export function selectAll(scope: Scope = globalScope): void {

Note: This requires Scope to be exported from ./circuit and the globalScope type to match.

@s1dhu98
Copy link
Contributor Author

s1dhu98 commented Jan 31, 2026

@tachyons kindly review the changes and merge the pull request if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant