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
@@ -241,7 +241,7 @@ class Channel {
debounce(
timeout: Duration(seconds: 1),
target: updateAttachment,
arguments: [
positionalArguments: [
it.copyWith(
uploadState: UploadState.inProgress(uploaded: sent, total: total),
),
@@ -1695,7 +1695,7 @@ class ChannelClientState {
debounce(
timeout: Duration(milliseconds: 500),
target: _channel._client.chatPersistenceClient?.updateChannelState,
arguments: [v],
positionalArguments: [v],
);
}
+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;