Add .off method to ApiBase (#999)
* Add .off method to ApiBase * Update CHANGELOG
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
- Update `ContractInfo` to match substrate master
|
||||
- Cater for `Vec`, `Option`, `Result`, tuples and fixed vectors for contracts ABIs
|
||||
- Additional examples for subscriptions using multi
|
||||
- Add `off` method to `ApiBase` to remove an event listener
|
||||
|
||||
# 0.81.1
|
||||
|
||||
|
||||
@@ -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