debounce static method
防抖
Implementation
static Function debounce(
Function func, {
String? id,
int timeout = _defaultDuration,
}) {
return () {
final String key = id ?? func.hashCode.toString();
Timer? timer = _funcDebounce[key];
if (timer == null) {
func.call();
timer = Timer(Duration(milliseconds: timeout), () {
Timer? t = _funcDebounce.remove(key);
t?.cancel();
t = null;
});
_funcDebounce[key] = timer;
}
};
}