Interface: IDelegate<TFunc>
Broker.IDelegate
A subscription. Used to subscribe callbacks to events.
Type parameters
| Name | Type | 
|---|---|
TFunc | extends Function | 
Hierarchy
- 
ISubscription<TFunc>↳
IDelegate 
Properties
fire
• fire: TFunc
Fire (Evoke)
Methods
subscribe
▸ subscribe(obj, member, singleshot?): void
Subscribe a callback function to this event. Subscribed callbacks are called when the event fires.
Parameters
| Name | Type | Description | 
|---|---|---|
obj | object | Object used as the this value bound to the callback function. | 
member | TFunc | Function called when the event is fired. | 
singleshot? | boolean | true if the subscription should be automatically removed after the first time it is fired. | 
Returns
void
Example
// Log 'Series data loaded!' to the console the next time the data loaded event fires and then unsubscribe automatically.
seriesApi.onDataLoaded().subscribe(null, () => { console.log('Series data loaded!'); }, true);
Subscribe to an event within a class. Manually unsubscribe when some condition is true.
class Example {
  constructor(seriesApi) {
    this._seriesApi = seriesApi;
    this._seriesApi.onDataLoaded().subscribe(this, this._onDataLoaded);
  }
  _onDataLoaded() {
    // Do something in response to the event.
    if (someUnsubscribeCondition) {
      this._seriesApi.onDataLoaded().unsubscribe(this, this._onDataLoaded);
    }
  }
}
Inherited from
unsubscribe
▸ unsubscribe(obj, member): void
Unsubscribe a previously subscribed callback function.
It is important that the obj and member arguments are the same as the ones passed when the callback was subscribed.
Parameters
| Name | Type | Description | 
|---|---|---|
obj | object | Object passed as the this value when the callback was subscribed. | 
member | TFunc | Function subscribed to the event. | 
Returns
void
Inherited from
unsubscribeAll
▸ unsubscribeAll(obj): void
Unsubscribe all callbacks that were subscribed with the same obj value.
Parameters
| Name | Type | Description | 
|---|---|---|
obj | object | obj value passed when the callbacks were subscribed. | 
Returns
void
Example
// Unsubscribe all three callback functions at once in the `destroy` method.
class Example {
  constructor(seriesApi) {
    this._seriesApi = seriesApi;
    this._seriesApi.onDataLoaded().subscribe(this, this._callback1);
    this._seriesApi.onDataLoaded().subscribe(this, this._callback2);
    this._seriesApi.onDataLoaded().subscribe(this, this._callback3);
  }
  destroy() {
    this._seriesapi.onDataLoaded().unsubscribeAll(this);
  }
  _callback1() { ... }
  _callback2() { ... }
  _callback3() { ... }
}