Simon Tucker
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?

)

    Simon Tucker

    Written by

    Watch out, he’s a byter

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade