debounce method
void
debounce(
- 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) {
final v = _lastValue.remove(key) as T?;
if (v != null) {
target?.call(v);
}
}
});
}