debounce method

void debounce(
  1. T value
)

Implementation

void debounce(T value) {
  final key = _generateKey();
  final hasTimer = _funcDebounce[key] != null;
  if (immediate && !hasTimer) {
    target?.call(value);
  } else {
    _lastValue[key] = value;
  }
  _funcDebounce[key]?.cancel();
  _funcDebounce[key] = Timer(Duration(milliseconds: timeout), () {
    final t = _funcDebounce.remove(key);
    t?.cancel();
    if (!immediate) {
      if (_lastValue.containsKey(key)) {
        final value = _lastValue.remove(key) as T;
        target?.call(value);
      }
    } else {
      _lastValue.remove(key);
    }
  });
}