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.
🚀 feat: Add throttle functionality to event tracking
Summary
This PR introduces comprehensive throttle functionality to the event-tracker library, complementing the existing debounce feature. Throttling ensures that functions are called at most once during a specified time interval, which is essential for performance optimization in high-frequency events like scrolling, resizing, or rapid user interactions.
✨ Features Added
Core Throttle Implementation
throttle
utility function (src/utils/throttle.ts
)Integration with Event Tracking System
track.onClick({ action: "test" }, { throttle: { delay: 100 } })
trackWithSchema.onClick(params, { throttle: { delay: 100, trailing: true } })
<Track.Click throttle={{ delay: 100 }} />
<Track.DOMEvent throttle={{ delay: 100, leading: false }} />
useTimingCache
hook for efficient function reuseConfiguration Options
🔄 Key Differences from Debounce
false
true
true
false
📝 Usage Examples
Basic Usage
Component Usage
Advanced Configuration
🏗️ Implementation Details
Type Safety
ThrottleConfig
andThrottledFunction
interfacesTrackingOptions
for both debounce and throttlePerformance Optimizations
useTimingCache
hook prevents creating new throttled instances on every renderBackward Compatibility
🧪 Testing
Comprehensive test coverage with 20+ test cases covering:
🔧 Technical Architecture
File Structure