I am working on organizing my custom channel logic into its own class. During the created
lifecycle method, I am executing each method in the class I created. However, I am facing a challenge in retaining the instance of the socket
that was created in the init() method for use in other methods.
Main.vue
import CustomClass from './CustomClass';
created() {
const customClass = new CustomClass();
customClass.init();
customClass.subscribe();
}
CustomClass.js
import Socket from 'Socket';
class CustomClass {
init() {
const socket = new Socket(key: XXXXX);
}
subscribe() {
// How can I access `socket` here after it was created in init?
socket.subscribe(channel: 'xxxx');
}
}