Skip to content

Commit aa1b9c1

Browse files
committed
destructing
1 parent 529ab3c commit aa1b9c1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

services/static-webserver/client/source/class/osparc/study/Conversations.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ qx.Class.define("osparc.study.Conversations", {
143143

144144
members: {
145145
__conversations: null,
146+
__wsHandlers: null,
146147

147148
_createChildControlImpl: function(id) {
148149
let control;
@@ -163,14 +164,15 @@ qx.Class.define("osparc.study.Conversations", {
163164
},
164165

165166
__listenToConversationWS: function() {
166-
const socket = osparc.wrapper.WebSocket.getInstance();
167+
this.__wsHandlers = [];
167168

169+
const socket = osparc.wrapper.WebSocket.getInstance();
168170
[
169171
"conversation:message:created",
170172
"conversation:message:update",
171173
"conversation:message:deleted",
172174
].forEach(eventName => {
173-
socket.on(eventName, message => {
175+
const eventHandler = message => {
174176
console.log("Conversation message", eventName, message);
175177
if (message) {
176178
const conversationId = message["conversationId"];
@@ -189,7 +191,9 @@ qx.Class.define("osparc.study.Conversations", {
189191
}
190192
}
191193
}
192-
}, this);
194+
};
195+
socket.on(eventName, eventHandler, this);
196+
this.__wsHandlers.push({ eventName, handler: eventHandler });
193197
});
194198
},
195199

@@ -261,5 +265,15 @@ qx.Class.define("osparc.study.Conversations", {
261265

262266
conversationsLayout.getChildControl("bar").add(newConversationButton);
263267
},
264-
}
268+
},
269+
270+
destruct: function() {
271+
const socket = osparc.wrapper.WebSocket.getInstance();
272+
if (this.__wsHandlers) {
273+
this.__wsHandlers.forEach(({ eventName }) => {
274+
socket.removeSlot(eventName);
275+
});
276+
this.__wsHandlers = null;
277+
}
278+
},
265279
});

0 commit comments

Comments
 (0)