Skip to content

JS to TS : simulator/src/data/load.ts #422 #422

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

Open
wants to merge 7 commits 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
6 changes: 6 additions & 0 deletions src/components/Panels/ElementsPanel/ElementsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@mouseleave="tooltipText = 'null'"
>
<img :src="element.imgURL" :alt="element.name" />

</div>
</div>
<v-expansion-panels
Expand Down Expand Up @@ -77,6 +78,7 @@
:src="element.imgURL"
:alt="element.name"
/>

</div>
</div>
</v-expansion-panel-text>
Expand Down Expand Up @@ -123,6 +125,10 @@
:src="element.imgURL"
:alt="element.name"
/>
<div class="overflow-hidden text-nowrap position-relative">
<p class=" d-inline-block">{{ element.name }}</p>
</div>

</div>
</div>
</v-expansion-panel-text>
Expand Down
48 changes: 43 additions & 5 deletions src/simulator/src/app.js → src/simulator/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
import { setup } from './setup'
import { setup } from './setup';

// Define interfaces for the structure
interface Device {
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?: (number | string)[];
}
Comment on lines +4 to +20
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

Expand device types and add JSDoc documentation.

The Device interface has a limited set of device types and lacks documentation for complex fields.

+/**
+ * Represents a device in the circuit simulator.
+ * @property type - The type of the device
+ * @property net - Network identifier
+ * @property order - Optional display order
+ * @property bits - Number of bits
+ * @property label - Optional device label
+ * @property abits - Optional address bits for memory devices
+ * @property words - Optional word count for memory devices
+ * @property memdata - Optional memory initialization data
+ */
 interface Device {
-    type: 'Input' | 'Output' | 'Memory';
+    type: 'Input' | 'Output' | 'Memory' | 'Register' | 'Counter' | 'Clock' | 'AndGate' | 'OrGate' | 'NotGate' | 'XorGate';
     // ... rest of the interface
 }
📝 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
interface Device {
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?: (number | string)[];
}
/**
* Represents a device in the circuit simulator.
* @property type - The type of the device
* @property net - Network identifier
* @property order - Optional display order
* @property bits - Number of bits
* @property label - Optional device label
* @property abits - Optional address bits for memory devices
* @property words - Optional word count for memory devices
* @property memdata - Optional memory initialization data
*/
interface Device {
type: 'Input' | 'Output' | 'Memory' | 'Register' | 'Counter' | 'Clock' | 'AndGate' | 'OrGate' | 'NotGate' | 'XorGate';
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?: (number | string)[];
}


interface Connector {
to: {
id: string;
port: string;
};
from: {
id: string;
port: string;
};
name: string;
}

interface Circuit {
devices: Record<string, Device>;
connectors: Connector[];
subcircuits: Record<string, unknown>;
}
Comment on lines +34 to +38
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

Avoid using unknown type.

The subcircuits field uses the unknown type, which bypasses TypeScript's type checking. Consider defining a proper type for subcircuits.

 interface Circuit {
     devices: Record<string, Device>;
     connectors: Connector[];
-    subcircuits: Record<string, unknown>;
+    subcircuits: Record<string, Circuit>;
 }
📝 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
interface Circuit {
devices: Record<string, Device>;
connectors: Connector[];
subcircuits: Record<string, unknown>;
}
interface Circuit {
devices: Record<string, Device>;
connectors: Connector[];
subcircuits: Record<string, Circuit>;
}


document.addEventListener('DOMContentLoaded', () => {
setup()
var js = {
setup();

const js: Circuit = {
devices: {
dev0: {
type: 'Input',
Expand Down Expand Up @@ -206,5 +244,5 @@ document.addEventListener('DOMContentLoaded', () => {
},
],
subcircuits: {},
}
})
};
});
293 changes: 0 additions & 293 deletions src/simulator/src/data/load.js

This file was deleted.

Loading