패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.3

easy_debounce

Dart/Flutter용 매우 사용하기 쉬운 메서드 호출 디바운싱 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
41만
좋아요
438
Pub 점수
150

패키지 설치

flutter pub add easy_debounce

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

easy_debounce는 메서드 호출 디바운싱 구현을 단순화하는 가벼운 Dart/Flutter 패키지입니다. 함수 실행을 지연시키는 직관적인 API를 제공하여 과도한 호출을 방지합니다. 검색 입력, 실시간 검증 또는 자주 발생하는 사용자 상호작용에 이상적입니다. 이 패키지는 Flutter 프로젝트에 원활하게 통합되며 모든 주요 플랫폼을 지원합니다. 최소한의 설정으로 개발자는 성능을 향상시키고 불필요한 처리를 줄일 수 있습니다.

사용 사례

  • 실시간 검색 필터링
  • 폼 입력 검증
  • API 요청 제한
  • 실시간 텍스트 처리
  • 사용자 상호작용 최적화

주요 기능

  • 간단한 한 줄 통합
  • 보류 중인 호출의 자동 취소
  • 크로스 플랫폼 지원
  • 최소한의 보일러플레이트
  • 깨끗하고 읽기 쉬운 구문

적합한 대상

  • 빠른 디바운스 솔루션을 찾는 개발자
  • 자주 UI가 업데이트되는 프로젝트
  • 입력 레이트 제한이 필요한 앱
  • 초보자가 상태 관리 배우기

고려 사항

  • 복잡한 타이밍 논리에 적합하지 않습니다
  • 기본 지연 외의 사용자 정의가 제한적입니다
  • Dart의 비동기 기능에 의존합니다
  • 경계 사례에 대한 추가 처리가 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

easy_debounce

An extremely easy-to-use method call debouncer, throttler, rate limiter package for Dart/Flutter.

Debouncing

Debouncing is needed when there is a possibility of multiple calls to a method being made within a short duration of each other, and it's desireable that only the last of those calls actually invoke the target method.

So basically each call starts a timer, and if another call happens before the timer executes, the timer is reset and starts waiting for the desired duration again. When the timer finally does time out, the target method is invoked.

Throttling

Throttling is sort of the opposite of debouncing - only the first call to a method actually invokes the method, and any subsequent calls that are made within a specified duration are ignored. This can be useful to throttle presses on a refresh button for example.

Rate limiting

Rate limiting is similar to throttling - the first call to a method actually invokes the method, and any subsequent calls that are made within a specified duration are recorded and the once the duration has elapsed then the last call will be executed. This can be useful to rate limit progress updates as you want the first, last and periodic updates in between.

Usage

Debouncing

Use the debouncer by calling debounce:

EasyDebounce.debounce(
    'my-debouncer',                 // <-- An ID for this particular debouncer
    Duration(milliseconds: 500),    // <-- The debounce duration
    () => myMethod()                // <-- The target method
);

The above call will invoke myMethod() after 500 ms, unless another call to debounce() with the same tag is made within 500 ms. A tag identifies this particular debouncer, which means you can have multiple different debouncers running concurrently and independent of each other.

Cancelling a debouncer

A debouncer which hasn't yet executed its target function can be called by calling cancel() with the debouncers tag:

EasyDebounce.cancel('my-debouncer');

To cancel all active debouncers, call cancelAll():

EasyDebounce.cancelAll();
Counting active debouncers

You can get the number of active debouncers (debouncers which haven't yet executed their target methods) by calling count():

print('Active debouncers: ${EasyDebounce.count()}'); 
Fire a debouncer target function manually

If you need to fire the target function of a debouncer before the timer executes, you can call fire():

EasyDebounce.fire('my-debouncer');

This will execute the debouncers target function, but the debounce timer will keep running unless you also call cancel().

Throttling

Use the throttler by calling throttle:

EasyThrottle.throttle(
    'my-throttler',                 // <-- An ID for this particular throttler
    Duration(milliseconds: 500),    // <-- The throttle duration
    () => myMethod()                // <-- The target method
    onAfter: (){ ... }              // <-- Optional callback, called after the duration has passed 
);

The above call will invoke myMethod() once, and any subsequent calls to throttle() with the same tag within 500 ms are ignored. A tag identifies this particular throttler, which means you can have multiple different throttlers running concurrently and independent of each other.

The onAfter callback will be invoked after the throttler is done, i.e. when the specified duration has passed and the throttler is no longer ignoring calls.

Cancelling a throttler

A throttler which hasn't yet executed its target function can be called by calling cancel() with the throttlers tag:

EasyThrottle.cancel('my-throttler');

To cancel all active throttlers, call cancelAll():

EasyThrottle.cancelAll();
Counting active throttlers

You can get the number of active throttlers (throttlers which are still ignoring subsequent calls to their target methods) by calling count():

print('Active throttlers: ${EasyThrottle.count()}'); 
Rate Limiting

Use the rate limiter by calling rateLimit:

EasyRateLimit.rateLimit(
    'my-ratelimiter',               // <-- An ID for this particular rate limiter
    Duration(milliseconds: 500),    // <-- The rate limiter duration
    () => myMethod()                // <-- The target method
    onAfter: (){ ... }              // <-- Optional callback, called after the duration has passed 
);

The above call will invoke myMethod() once, and any subsequent calls to rateLimit() with the same tag within 500 ms are recorded, after 500 ms has elapsed the last call will be executed until no calls have been made within the subsequent 500 ms durations. A tag identifies this particular rate limiter, which means you can have multiple different rate limiters running concurrently and independent of each other.

The onAfter callback will be invoked on duration after the rate limiter has no calls to execute.

Cancelling a rate limiter

A rate limiter which is waiting for the duration to pass can be called by calling cancel() with the rate limiter tag:

EasyRateLimit.cancel('my-ratelimiter');

To cancel all active rate limiters, call cancelAll():

EasyRateLimit.cancelAll();
Counting active rate limiter

You can get the number of active rate limiters (rate limiters which are still ignoring subsequent calls to their target methods) by calling count():

print('Active rate limiters: ${EasyRateLimit.count()}'); 

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트