Aug 23, 2017 · 1 min read
Thanks, Kaushik.
If I understand your question correctly, you’re wondering how to unsubscribe from a single subscription instead of using wsclient.unsubscribeAll()?
When you use subscribeToMore it returns a function that when called should unsubscribe the subscription. For example, in Chatty, we unsubscribe/resubscribe to messageAdded whenever a new Group is added because we need to listen for messages in the new Group as well.
Looks something like this:
// group size has changed ~ we've added or removed a group
// we need to change subscription to account for new set of groups
if (nextProps.user.groups.length !== this.props.user.groups.length){
// unsubscribe from old
if (typeof this.messagesSubscription === 'function') {
this.messagesSubscription();
}
// subscribe to new
if (nextProps.user.groups.length) {
this.messagesSubscription = nextProps.subscribeToMessages();
}
}Does that answer your question?
