Skip to content

Commit

Permalink
Merge pull request #1492 from tradingview/fix-plugin-base-data-update…
Browse files Browse the repository at this point in the history
…-subscriber

plugin examples: fix plugin base _fireDataUpdated #1491
  • Loading branch information
romfrancois authored Jan 8, 2024
2 parents 61d45db + 2e2425c commit 54e9b61
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugin-examples/src/plugins/plugin-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class PluginBase implements ISeriesPrimitive<Time> {
}

public detached() {
this._series?.unsubscribeDataChanged(this._fireDataUpdated);
this._chart = undefined;
this._series = undefined;
this._requestUpdate = undefined;
Expand All @@ -41,7 +42,10 @@ export abstract class PluginBase implements ISeriesPrimitive<Time> {
return ensureDefined(this._series);
}

private _fireDataUpdated(scope: DataChangedScope) {
// This method is a class property to maintain the
// lexical 'this' scope (due to the use of the arrow function)
// and to ensure its reference stays the same, so we can unsubscribe later.
private _fireDataUpdated = (scope: DataChangedScope) => {
if (this.dataUpdated) {
this.dataUpdated(scope);
}
Expand Down

0 comments on commit 54e9b61

Please sign in to comment.