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

View File

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