Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleUnsubscribe(event) {
const { channel } = event.detail;
let foundIndex = -1;
const subscription = this.subscriptions.find((sub, index) => {
if (sub.channel === channel) {
foundIndex = index;
return true;
}
return false;
});
if (foundIndex !== -1) {
unsubscribe(subscription, response => {
if (response.successful) {
this.notify(
'success',
'Successfully unsubscribed',
channel
);
} else {
this.notify('error', 'Failed to unsubscribe', channel);
console.error(JSON.stringify(response));
}
});
this.subscriptions.splice(foundIndex, 1);
}
}
this.subscriptions.forEach(subscription => {
unsubscribe(subscription, response => {
if (!response.successful) {
console.error(JSON.stringify(response));
}
});
});
this.subscriptions = [];