-
-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: Refactor sync modifiers to use shared Data1D processing logic #193
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
base: main
Are you sure you want to change the base?
Conversation
- Extract common Data1D processing logic into processData1D() helper function - Refactor synccomputesmodifier.ts, syncfixesmodifier.ts, and syncvariablesmodifier.ts to use shared function - Reduce code duplication from ~125 lines to ~70-73 lines per file - Maintain all unique logic (execute checks, sync calls, name array handling) Closes #186
|
Cursor Agent can help with this pull request. Just |
|
/gemini review |
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.
Code Review
This pull request is a great refactoring that significantly reduces code duplication by extracting shared logic into a processData1D helper function. This improves maintainability and consistency across the sync modifiers. My review includes a few minor suggestions for the new helper function to enhance performance and readability.
- Optimize size() call: store data1DNamesSize once instead of calling twice - Remove redundant check: currentData1D is guaranteed to be an object - Replace magic number 4 with Float32Array.BYTES_PER_ELEMENT for clarity
|
/gemini review |
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.
Code Review
This is an excellent refactoring that significantly reduces code duplication by introducing the processData1D helper function. This greatly improves maintainability and consistency across the sync modifiers. The changes are clear and follow the stated goals in the pull request description. I have one minor suggestion to improve the readability of the data processing loop in the new helper function.
| for (let k = lengthBeforeWeStart; k < xValues.length; k++) { | ||
| if (j === 0) { | ||
| currentData1D.data.push([xValues[k]]); | ||
| } | ||
| currentData1D.data[k].push(yValues[k]); | ||
| } |
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.
The current logic for populating currentData1D.data is functionally correct, but it could be made more explicit to improve readability. By using an if/else block, you can clearly separate the logic for initializing a new row (for j === 0) from appending to an existing row (for j > 0). This makes the intent of the code easier to grasp at a glance.
| for (let k = lengthBeforeWeStart; k < xValues.length; k++) { | |
| if (j === 0) { | |
| currentData1D.data.push([xValues[k]]); | |
| } | |
| currentData1D.data[k].push(yValues[k]); | |
| } | |
| for (let k = lengthBeforeWeStart; k < xValues.length; k++) { | |
| if (j === 0) { | |
| currentData1D.data.push([xValues[k], yValues[k]]); | |
| } else { | |
| currentData1D.data[k].push(yValues[k]); | |
| } | |
| } |
Use if/else block to clearly separate logic for initializing new row (j === 0) from appending to existing row (j > 0)
Summary
Fixes #186
Refactors all three sync modifiers to use the shared
processData1D()helper function, reducing each file from ~125 lines to ~50-60 lines.Changes
Refactored:
src/modifiers/synccomputesmodifier.tssrc/modifiers/syncfixesmodifier.tssrc/modifiers/syncvariablesmodifier.tsEach modifier now:
syncComputes,syncFixes, orsyncVariables)getComputeNames,getFixNames, orgetVariableNames)processData1D()function for Data1D processingBenefits
Prerequisites
Requires #185 to be completed first (extraction of shared Data1D processing logic).
This pull request contains changes generated by a Cursor Cloud Agent