add support for named args

This commit is contained in:
Salvatore Giordano
2021-03-01 11:59:20 +01:00
parent b36c31c992
commit 074629a7f0
2 changed files with 9 additions and 4 deletions
+7 -2
View File
@@ -9,14 +9,19 @@ Map<Function, Timer> timeouts = {};
void debounce({
@required Duration timeout,
@required Function target,
@required List arguments,
List positionalArguments,
Map<Symbol, dynamic> namedArguments,
}) {
if (timeouts.containsKey(target)) {
timeouts[target].cancel();
}
final timer = Timer(timeout, () {
Function.apply(target, arguments);
Function.apply(
target,
positionalArguments,
namedArguments,
);
});
timeouts[target] = timer;