Refactor TypeScript implementation to eliminate code duplication#34
Refactor TypeScript implementation to eliminate code duplication#34lookbusy1344 merged 6 commits intomainfrom
Conversation
- Added pionRocketFuelFractionsMultiple() to calculate multiple fuel fractions at once - Extracted createVelocityGradient() helper for gradient creation - Extracted createArrowIndicators() helper for arrow indicator calculations - Extracted createMassRemainingDatasets() helper for fuel chart datasets - Reduced code duplication across dataGeneration.ts, eventHandlers.ts, and charts.ts Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
- Added createDualTimeDatasets() helper for proper/coordinate time chart datasets - Applied to velocity, rapidity, and time dilation charts - Further reduced code duplication in acceleration and flip-burn chart updates - Bundle size reduced from 315.24 kB to 314.06 kB Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
|
Is the code now optimally refactored? Do a code review @copilot |
- Removed unnecessary conversion from percentage to fraction and back - Simplified to direct calculation: 100 - fuelPercent - Bundle size further reduced to 313.99 kB Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
- Clarified JSDoc comment for pionRocketFuelFractionsMultiple to specify percentages - Optimized createArrowIndicators to use Set for O(1) lookups instead of O(n) indexOf - Bundle size further reduced to 313.97 kB Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
- Added ChartDataset type for better type safety - Optimized createArrowIndicators with Map for O(1) index lookups - All dataset helper functions now properly typed - Bundle size: 314.00 kB Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
The code is well-refactored with excellent improvements already made. I've identified a few remaining optimization opportunities: Further optimizations possible:
const COLORS = {
CYAN: '#00d9ff',
GREEN: '#00ff9f',
AMBER: '#ffaa00',
// etc.
}
However, these are minor improvements. The current refactoring already achieves:
The remaining patterns would save ~10-20 more lines but with diminishing returns. The code is production-ready as-is. Commit: d058470 |
The TypeScript implementation contained significant code duplication in fuel fraction calculations, chart dataset configurations, and gradient creation logic.
Changes
Extracted helper functions
pionRocketFuelFractionsMultiple()- Calculates fuel fractions at multiple efficiency levels (40%, 50%, 60%, 70%) in a single call, eliminating 8+ repetitive calculation blockscreateVelocityGradient()- Creates velocity-based gradients with configurable color schemes, removing 3 duplicate implementationscreateArrowIndicators()- Generates arrow indicator properties for trajectory visualizations with O(1) lookups via Set/Map instead of O(n) indexOf operationscreateMassRemainingDatasets()- Standardizes fuel chart dataset configuration across acceleration and flip-burn modescreateDualTimeDatasets()- Consolidates 6 instances of proper time vs coordinate time dataset configurationsType safety improvements
ChartDatasettype definition to replaceany[]return typesExample
Before:
After:
Impact
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.