Add .off method to ApiBase (#999)

* Add .off method to ApiBase

* Update CHANGELOG
This commit is contained in:
Axel Chalon
2019-06-13 18:34:47 +02:00
committed by Jaco Greeff
parent ac7acc9254
commit 5533b1b961
2 changed files with 28 additions and 0 deletions
+27
View File
@@ -315,6 +315,33 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
return this;
}
/**
* @description Remove the given eventemitter handler
*
* @param type The type of event the callback was attached to. Available events are `connected`, `disconnected`, `ready` and `error`
* @param handler The callback to unregister.
*
* @example
* <BR>
*
* ```javascript
* const handler = () => {
* console.log('Connected !);
* };
*
* // Start listening
* api.on('connected', handler);
*
* // Stop listening
* api.off('connected', handler);
* ```
*/
off (type: ApiInterface$Events, handler: (...args: Array<any>) => any): this {
this._eventemitter.removeListener(type, handler);
return this;
}
/**
* @description Attach an one-time eventemitter handler to listen to a specific event
*