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( debounce(
timeout: Duration(seconds: 1), timeout: Duration(seconds: 1),
target: updateAttachment, target: updateAttachment,
arguments: [ positionalArguments: [
it.copyWith( it.copyWith(
uploadState: UploadState.inProgress(uploaded: sent, total: total), uploadState: UploadState.inProgress(uploaded: sent, total: total),
), ),
@@ -1695,7 +1695,7 @@ class ChannelClientState {
debounce( debounce(
timeout: Duration(milliseconds: 500), timeout: Duration(milliseconds: 500),
target: _channel._client.chatPersistenceClient?.updateChannelState, target: _channel._client.chatPersistenceClient?.updateChannelState,
arguments: [v], positionalArguments: [v],
); );
} }
+7 -2
View File
@@ -9,14 +9,19 @@ Map<Function, Timer> timeouts = {};
void debounce({ void debounce({
@required Duration timeout, @required Duration timeout,
@required Function target, @required Function target,
@required List arguments, List positionalArguments,
Map<Symbol, dynamic> namedArguments,
}) { }) {
if (timeouts.containsKey(target)) { if (timeouts.containsKey(target)) {
timeouts[target].cancel(); timeouts[target].cancel();
} }
final timer = Timer(timeout, () { final timer = Timer(timeout, () {
Function.apply(target, arguments); Function.apply(
target,
positionalArguments,
namedArguments,
);
}); });
timeouts[target] = timer; timeouts[target] = timer;