-
Notifications
You must be signed in to change notification settings - Fork 152
refactor : typescript integration in src/simulator/src/app.ts #431
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { setUserKeys } from '../model/actions' | ||
|
||
/** | ||
* Update the hotkey panel UI with the currently set configuration | ||
* @param mode User preferred configuration or default keys | ||
*/ | ||
export const updateHTML = (mode: 'user' | 'default'): void => { | ||
const preferenceContainer = document.getElementById('preference') | ||
if (!preferenceContainer) return | ||
|
||
if (mode === 'user') { | ||
const userKeys = localStorage.get('userKeys') as Record<string, string> | ||
const children = preferenceContainer.children | ||
|
||
for (let x = 0; x < children.length; x++) { | ||
const child = children[x] as HTMLElement | ||
const keyElement = child.querySelector('.key-name') as HTMLElement | ||
const valueElement = child.querySelector('.key-value') as HTMLElement | ||
|
||
if (keyElement && valueElement) { | ||
valueElement.innerText = userKeys[keyElement.innerText] || '' | ||
} | ||
} | ||
} else if (mode === 'default') { | ||
const defaultKeys = localStorage.get('defaultKeys') as Record<string, string> | ||
const children = preferenceContainer.children | ||
|
||
for (let x = 0; x < children.length; x++) { | ||
const child = children[x] as HTMLElement | ||
const keyElement = child.querySelector('.key-name') as HTMLElement | ||
const valueElement = child.querySelector('.key-value') as HTMLElement | ||
|
||
if (keyElement && valueElement) { | ||
valueElement.innerText = defaultKeys[keyElement.innerText] || '' | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Override key of duplicate entries | ||
* @param combo Key combination to override | ||
*/ | ||
export const override = (combo: string): void => { | ||
const preferenceContainer = document.getElementById('preference') | ||
if (!preferenceContainer) return | ||
|
||
const children = preferenceContainer.children | ||
for (let x = 0; x < children.length; x++) { | ||
const child = children[x] as HTMLElement | ||
const valueElement = child.querySelector('.key-value') as HTMLElement | ||
|
||
if (valueElement && valueElement.innerText === combo) { | ||
valueElement.innerText = '' | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Close the edit interface | ||
*/ | ||
export const closeEdit = (): void => { | ||
const pressedKeysElement = document.getElementById('pressedKeys') | ||
const editElement = document.getElementById('edit') | ||
|
||
if (pressedKeysElement) pressedKeysElement.textContent = '' | ||
if (editElement) editElement.style.display = 'none' | ||
} | ||
|
||
/** | ||
* Submit user key configurations | ||
*/ | ||
export const submit = (): void => { | ||
const editElement = document.getElementById('edit') | ||
if (editElement) editElement.style.display = 'none' | ||
|
||
setUserKeys() | ||
updateHTML('user') | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
type DeviceType = 'Input' | 'Output' | 'Memory'; | ||
|
||
interface Device { | ||
type: DeviceType; | ||
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 Endpoint { | ||
id: string; | ||
port: string; | ||
} | ||
|
||
interface Connector { | ||
to: Endpoint; | ||
from: Endpoint; | ||
name: string; | ||
} | ||
|
||
export interface CircuitConfiguration { | ||
devices: {[key: string]: Device}; | ||
connectors: Connector[]; | ||
subcircuits: Record<string, unknown>; | ||
} | ||
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve type safety of the CircuitConfiguration interface. Two potential improvements:
Consider this refactor: // If you have a specific set of device IDs
type DeviceId = string; // Or a more specific union type if applicable
// If subcircuits have a specific structure
interface Subcircuit {
// Add appropriate properties
}
export interface CircuitConfiguration {
devices: Record<DeviceId, Device>;
connectors: Connector[];
subcircuits: Record<string, Subcircuit>;
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
🧩 Analysis chain
Verify if the DeviceType union type covers all possible device types.
Please confirm that these are all the possible device types in the circuit simulator. Common device types that might be missing: 'Gate', 'FlipFlop', 'Counter', etc.
🏁 Script executed:
Length of output: 1144
DeviceType union missing at least one reported device type.
src/simulator/src/types/app.types.ts
is defined as'Input' | 'Output' | 'Memory'
.Counter
is being used (insrc/simulator/src/modules/Counter.js
) as an object type, yet it isn’t included in the union.'Gate'
,'FlipFlop'
) should also be added.