When you find yourself writing similar code patterns multiple times, extract them into reusable methods, constants, or leverage existing helpers. This improves maintainability and reduces the chance of inconsistencies.
Examples of what to extract:
// Extract to: private _enqueueFrames(count: number, buffer: Buffer) { for (let i = 0; i < count; ++i) this._frameQueue.push(buffer); }
2. **Magic values used multiple times** - Use constants:
```typescript
// Instead of repeating colors:
const color = elements.length > 1 ? '#f6b26b7f' : '#6fa8dc7f';
// Use constants:
const HIGHLIGHT_COLOR_MULTIPLE = '#f6b26b7f';
const HIGHLIGHT_COLOR_SINGLE = '#6fa8dc7f';
// Instead of custom implementation, use existing helper:
const callLocation = wrapFunctionWithLocation((location: Location, ...args) =>
this._modifier('skip', location, ...args)
);
// Instead of retrieving from map twice:
const data = this._dataByTestId.get(params.testId);
this._updateTest(data); // Pass the data directly
Enter the URL of a public GitHub repository