Bind method to 'this' so that its listeners are correctly unbound on destroy (#3948)

* Bind method to 'this' so that its listener can work correctly
* Bind this for toggling subscriptions as well
This commit is contained in:
Shefali Joshi 2021-06-21 10:44:59 -07:00 committed by GitHub
parent 6755ef4641
commit fa5aceb7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,15 +27,17 @@ export default class StyleRuleManager extends EventEmitter {
super();
this.openmct = openmct;
this.callback = callback;
this.refreshData = this.refreshData.bind(this);
this.toggleSubscription = this.toggleSubscription.bind(this);
if (suppressSubscriptionOnEdit) {
this.openmct.editor.on('isEditing', this.toggleSubscription.bind(this));
this.openmct.editor.on('isEditing', this.toggleSubscription);
this.isEditing = this.openmct.editor.editing;
}
if (styleConfiguration) {
this.initialize(styleConfiguration);
if (styleConfiguration.conditionSetIdentifier) {
this.openmct.time.on("bounds", this.refreshData.bind(this));
this.openmct.time.on("bounds", this.refreshData);
this.subscribeToConditionSet();
} else {
this.applyStaticStyle();