Feathers: Unsubscribing to a service subscription is not available (client)

Created on 3 Jul 2016  Â·  6Comments  Â·  Source: feathersjs/feathers

Hey guys,

When using the 'on' handler for a Feathers service, there's no way to unsubscribe using the Feathers service API.

My particular use case is in React:

componentDidMount(props) { this.userService = userService.on('updated', (newUser) => { // Some code here };
}
`

I'd like to basically do:

componentWillUnmount() { this.userService.unsubscribe("updated") }

And currently I don't believe thats supported. Any help here would be appreciated.

Thanks.

-Tom

Most helpful comment

I made a fix in https://github.com/feathersjs/feathers-socket-commons/pull/23 that should now enable all available EventEmitter methods (including off).

All 6 comments

All services are an EventEmitter. Unsubscribing can be done using removeListener or removeAllListeners:

componentWillUnmount() {
  this.userService.removeListener("updated", this.updateListener);
}

componentWillUnmount() {
  this.userService.removeAllListeners("updated");
}

Thank you for the quick response.

I'm just finishing some hardcore sprinting on a project in chatbots.

As soon as I'm done with this sprint I'd love to help you with feathers.

I think you're doing an awesome job.

Let me know how I can help.

-Tom

Sent from my iPhone

On Jul 3, 2016, at 11:15 PM, David Luecke [email protected] wrote:

All services are an EventEmitter. Unsubscribing can be done using removeListener or removeAllListeners:

componentWillUnmount() {
this.userService.removeListener("updated", this.updateListener);
}

componentWillUnmount() {
this.userService.removeAllListeners("updated");
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Btw - just checked and it seems that the user service does not have either of those methods…

This is using feathers on the client btw.

Any ideas?

Tom Kornblit

On Jul 4, 2016, at 12:02 AM, Tom Kornblit tom.[email protected] wrote:

Thank you for the quick response.

I'm just finishing some hardcore sprinting on a project in chatbots.

As soon as I'm done with this sprint I'd love to help you with feathers.

I think you're doing an awesome job.

Let me know how I can help.

-Tom

Sent from my iPhone

On Jul 3, 2016, at 11:15 PM, David Luecke <[email protected] notifications@github.com> wrote:

All services are an EventEmitter https://nodejs.org/dist/latest-v6.x/docs/api/events.html#events_class_eventemitter. Unsubscribing can be done using removeListener https://nodejs.org/dist/latest-v6.x/docs/api/events.html#events_emitter_removelistener_eventname_listener or removeAllListeners https://nodejs.org/dist/latest-v6.x/docs/api/events.html#events_emitter_removealllisteners_eventname:

componentWillUnmount() {
this.userService.removeListener("updated", this.updateListener);
}

componentWillUnmount() {
this.userService.removeAllListeners("updated");
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/feathersjs/feathers/issues/362#issuecomment-230196955, or mute the thread https://github.com/notifications/unsubscribe/AB7b-RosLmqYqbyCLmqI2G9Af-LEet_Lks5qSHq1gaJpZM4JD84h.

Ah yes, sorry, it's off instead of removeEventListener for the socket client. I created a follow-up issue in https://github.com/feathersjs/feathers-socket-commons/issues/22.

And thank you! We'd definitely appreciate any help we can get 😄

I made a fix in https://github.com/feathersjs/feathers-socket-commons/pull/23 that should now enable all available EventEmitter methods (including off).

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arve0 picture arve0  Â·  4Comments

intumwa picture intumwa  Â·  3Comments

harrytang picture harrytang  Â·  3Comments

huytran0605 picture huytran0605  Â·  3Comments

rstegg picture rstegg  Â·  3Comments