tracker-component icon indicating copy to clipboard operation
tracker-component copied to clipboard

Update index.jsx

Open Elviron opened this issue 9 years ago • 3 comments

Save the subscriptions based on only the name of the subscription. So you don't save multiple subscriptions of the same name.

Elviron avatar Jun 06 '16 09:06 Elviron

With this, it isn't possible to have multiple subscriptions to the same publication in the same component. I think it's better to wrap the subscribe call in a autorun, since subscription inside autoruns will automatically stopped if the autorun will rerun.

maxnowack avatar Jun 06 '16 09:06 maxnowack

Great idea @maxnowack, that would remove the need to track the subscriptions on each component, and reduce the load on GC too. So the implementation would rather be:

this.autorun(() => this.__subscribe.apply(this, [name, ...options]))

Rather than the current lookup and removal. What do you think @Elviron ?

timbrandin avatar Jun 06 '16 11:06 timbrandin

@timbrandin I don't think that it is a good idea to wrap every subscribe in an autorun. If you take a look at the implementation in blaze, you'll see that the subscription handle will be saved as a reference and the subscription will be stopped if the view gets destroyed (Tracker.Component does something similar with tracker computations). In my opinion, this is the most flexible way. I could provide a PR for this.

PS: I don't get why you stringify the arguments of the subscriptions to store the reference. Is there a reason for this?

maxnowack avatar Jun 06 '16 12:06 maxnowack