From 2fc28d6a853b74347b9b4d02e88de6c60bec876b Mon Sep 17 00:00:00 2001 From: Jumper Chen Date: Thu, 15 Feb 2024 15:02:01 +0800 Subject: [PATCH] Resolved #334 Socket.on... returns disposer function --- CHANGELOG.md | 1 + README.md | 15 +++---------- lib/src/darty.dart | 52 +++++++++++++++++++++++----------------------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e47c238..4cef89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#55](https://github.com/rikulo/socket.io-client-dart/issues/55) how to custom parser * [#322](https://github.com/rikulo/socket.io-client-dart/pull/322) added emitWithAckAsync +* [#334](https://github.com/rikulo/socket.io-client-dart/pull/334) Socket.on... returns disposer function ## 2.0.3+1 diff --git a/README.md b/README.md index ea9878e..575e2ea 100644 --- a/README.md +++ b/README.md @@ -278,15 +278,6 @@ Contribution of all kinds is welcome. Please read [Contributing.md](https://gith ## Contributors -- Thanks [@felangel](https://github.com/felangel) for https://github.com/rikulo/socket.io-client-dart/issues/7 -- Thanks [@Oskang09](https://github.com/Oskang09) for https://github.com/rikulo/socket.io-client-dart/issues/21 -- Thanks [@bruce3x](https://github.com/bruce3x) for https://github.com/rikulo/socket.io-client-dart/issues/25 -- Thanks [@Kavantix](https://github.com/Kavantix) for https://github.com/rikulo/socket.io-client-dart/issues/26 -- Thanks [@luandnguyen](https://github.com/luandnguyen) for https://github.com/rikulo/socket.io-client-dart/issues/59 -- Thanks [@jorgefspereira](https://github.com/jorgefspereira) for https://github.com/rikulo/socket.io-client-dart/pull/177 -- Thanks [@fzyzcjy](https://github.com/fzyzcjy) for https://github.com/rikulo/socket.io-client-dart/pull/188 -- Thanks [@darwin-morocho](https://github.com/darwin-morocho) for https://github.com/rikulo/socket.io-client-dart/pull/189 -- Thanks [@chatziko](https://github.com/chatziko) for https://github.com/rikulo/socket.io-client-dart/pull/237 -- Thanks [@Astray-git](https://github.com/Astray-git) for https://github.com/rikulo/socket.io-client-dart/pull/313 -- Thanks [@Astray-git](https://github.com/Astray-git) for https://github.com/rikulo/socket.io-client-dart/pull/310 -- Thanks [@Frank3K](https://github.com/Frank3K) for https://github.com/rikulo/socket.io-client-dart/pull/338 + + + diff --git a/lib/src/darty.dart b/lib/src/darty.dart index 021719e..7d56c9a 100644 --- a/lib/src/darty.dart +++ b/lib/src/darty.dart @@ -8,56 +8,56 @@ import 'package:socket_io_common/src/util/event_emitter.dart'; /// Default event listeners for dart way API. extension DartySocket on Socket { - void onConnect(EventHandler handler) { - on('connect', handler); + Function() onConnect(EventHandler handler) { + return on('connect', handler); } - void onConnectError(EventHandler handler) { - on('connect_error', handler); + Function() onConnectError(EventHandler handler) { + return on('connect_error', handler); } - void onConnectTimeout(EventHandler handler) { - on('connect_timeout', handler); + Function() onConnectTimeout(EventHandler handler) { + return on('connect_timeout', handler); } - void onConnecting(EventHandler handler) { - on('connecting', handler); + Function() onConnecting(EventHandler handler) { + return on('connecting', handler); } - void onDisconnect(EventHandler handler) { - on('disconnect', handler); + Function() onDisconnect(EventHandler handler) { + return on('disconnect', handler); } - void onError(EventHandler handler) { - this.io.on('error', handler); + Function() onError(EventHandler handler) { + return this.io.on('error', handler); } - void onReconnect(EventHandler handler) { - this.io.on('reconnect', handler); + Function() onReconnect(EventHandler handler) { + return this.io.on('reconnect', handler); } - void onReconnectAttempt(EventHandler handler) { - this.io.on('reconnect_attempt', handler); + Function() onReconnectAttempt(EventHandler handler) { + return this.io.on('reconnect_attempt', handler); } - void onReconnectFailed(EventHandler handler) { - this.io.on('reconnect_failed', handler); + Function() onReconnectFailed(EventHandler handler) { + return this.io.on('reconnect_failed', handler); } - void onReconnectError(EventHandler handler) { - this.io.on('reconnect_error', handler); + Function() onReconnectError(EventHandler handler) { + return this.io.on('reconnect_error', handler); } - void onReconnecting(EventHandler handler) { - on('reconnecting', handler); + Function() onReconnecting(EventHandler handler) { + return on('reconnecting', handler); } - void onPing(EventHandler handler) { - this.io.on('ping', handler); + Function() onPing(EventHandler handler) { + return this.io.on('ping', handler); } - void onPong(EventHandler handler) { - on('pong', handler); + Function() onPong(EventHandler handler) { + return on('pong', handler); } }