Skip to content

anycable-client remove "on" events #148

Answered by palkan
Renmang asked this question in Q&A
Discussion options

You must be logged in to vote

Should the channel.disconnect() take care about removing the event?

Nope. We do not make any assumptions regarding when to remove event listeners; you might want to reconnect the same channel instance later again and keep your listeners. Thus, you need to take care of removing listeners yourself. In your case:

let unbindMessage = channel.on('message', handleMessage);
return () => {
  unbindMessage();
  channel.disconnect();
};

When i do the channel.disconnect() if that returns true, should i call consumer.cache.delete('CardChannel', { id }) myself?

Yes. See this note from the Readme:

Please, keep in mind, that cache is not cleared automatically. That's your responsibility...

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Renmang
Comment options

@palkan
Comment options

@palkan
Comment options

@Renmang
Comment options

Answer selected by Renmang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants