-
Notifications
You must be signed in to change notification settings - Fork 152
refactor : typescript integration in src/simulator/src/app.ts #459
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
Conversation
WalkthroughThe pull request introduces enhanced type safety in the simulator’s TypeScript code. In app.ts, a new import brings in the JsConfig type, and the variable declaration is updated from var to a strongly typed const with JsConfig. A semicolon is added for stylistic consistency in the setup() call. In app.types.ts, three interfaces—Device, Connector, and JsConfig—are added to define the structure of related configuration objects. The overall control flow remains unchanged. Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/simulator/src/types/app.types.ts (3)
1-13
: Consider enhancing type safety and documentation.
- Consider using string literal types for the
type
property to restrict valid values (e.g., 'Input', 'Output', 'Memory').- Consider using the more conventional
T[]
syntax instead ofArray<T>
for array types.- Consider adding JSDoc comments to document the purpose of each property.
+/** Interface representing a device in the simulator */ interface Device { + /** Type of the device (e.g., 'Input', 'Output', 'Memory') */ - type: string; + type: 'Input' | 'Output' | 'Memory'; net?: string; order?: number; bits: number; label?: string; abits?: number; words?: number; offset?: number; - rdports?: Array<{ clock_polarity?: boolean }>; - wrports?: Array<{ clock_polarity?: boolean }>; - memdata?: Array<number | string>; + rdports?: { clock_polarity?: boolean }[]; + wrports?: { clock_polarity?: boolean }[]; + memdata?: (number | string)[]; }
15-25
: Consider extracting common structure and adding documentation.Extract the common structure into a separate interface and add JSDoc comments for better documentation.
+/** Represents a connection point in the circuit */ +interface ConnectionPoint { + /** Unique identifier of the device */ + id: string; + /** Port name on the device */ + port: string; +} + +/** Interface representing a connection between two devices */ interface Connector { - to: { - id: string; - port: string; - }; - from: { - id: string; - port: string; - }; + /** Target connection point */ + to: ConnectionPoint; + /** Source connection point */ + from: ConnectionPoint; + /** Name of the connection */ name: string; }
27-33
: Consider adding documentation and improving type safety.
- Add JSDoc comments to document the purpose of each property.
- Consider using a more specific type for
subcircuits
instead ofunknown
.+/** Configuration interface for the JavaScript simulator */ export interface JsConfig { + /** Map of device IDs to their configurations */ devices: { [key: string]: Device; }; + /** List of connections between devices */ connectors: Connector[]; - subcircuits: Record<string, unknown>; + /** Map of subcircuit IDs to their configurations */ + subcircuits: Record<string, JsConfig>; }src/simulator/src/app.ts (1)
6-210
: LGTM! Consider extracting the configuration.The changes improve type safety by:
- Using
const
to prevent accidental reassignment- Adding type annotation to ensure configuration matches expected structure
Consider extracting the configuration object to a separate file to improve maintainability.
+// src/simulator/src/config/default.ts +import { JsConfig } from '../types/app.types'; + +export const defaultConfig: JsConfig = { + devices: { + // ... current devices configuration + }, + connectors: [ + // ... current connectors configuration + ], + subcircuits: {}, +}; // src/simulator/src/app.ts +import { defaultConfig } from './config/default'; document.addEventListener('DOMContentLoaded', () => { setup(); - const js: JsConfig = { - // ... large configuration object - }; + const js: JsConfig = defaultConfig; });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/simulator/src/app.ts
(2 hunks)src/simulator/src/types/app.types.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Redirect rules - circuitverse
- GitHub Check: Header rules - circuitverse
- GitHub Check: Pages changed - circuitverse
- GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
src/simulator/src/app.ts (2)
1-2
: LGTM!The imports are correctly structured and necessary for the TypeScript integration.
5-5
: LGTM!The semicolon addition improves code style consistency.
Fixes #414
@JoshVarga @niladrix719
Summary by CodeRabbit