함수: injectThrottledCallback()
function injectThrottledCallback<TFn>(fn, options): (...args) => void;
정의 위치: angular-pacer/src/throttler/injectThrottledCallback.ts:39
콜백 함수의 스로틀 버전을 생성하는 Angular 함수입니다.
이 함수는 injectThrottler를 래핑하여 기본 스로틀 요구 사항에 맞는 간소화된 API를 제공하는
래퍼입니다.
스로틀된 함수는 지정된 대기 시간 안에 최대 한 번 실행됩니다. 대기 시간 안에 여러 번 호출되면 첫 번째 호출(leading이 활성화된 경우) 또는 마지막 호출(trailing이 활성화된 경우)만 실행됩니다.
이 함수는 injectThrottler보다 간단한 API를 제공하므로 기본
스로틀에 적합합니다. 하지만 내부 Throttler 인스턴스를 노출하지 않습니다.
다음과 같은 기능이 필요한 고급 사용 사례에서는:
- 수동 취소
- 실행 횟수 확인
- 상태 추적
대신 injectThrottler 함수 사용을 고려합니다.
타입 매개변수
TFn
TFn extends AnyFunction
매개변수
fn
TFn
options
ThrottlerOptions<TFn>
반환값
(...args): void;
매개변수
args
...Parameters<TFn>
반환값
void
예시
// Throttle a scroll handler
const handleScroll = injectThrottledCallback((scrollY: number) => {
updateScrollPosition(scrollY);
}, {
wait: 100 // Execute at most once per 100ms
});
// Use in an event listener
window.addEventListener('scroll', () => {
handleScroll(window.scrollY);
});