Add .off method to ApiBase (#999)
* Add .off method to ApiBase * Update CHANGELOG
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user