meteor-mysql icon indicating copy to clipboard operation
meteor-mysql copied to clipboard

Template-Level Subscriptions

Open deejross opened this issue 9 years ago • 5 comments

From what I've read, the new recommendation is to create subscriptions in the Template.onCreated() callbacks using the "this.subscribe()" function. Right now it would appear that using "new MysqlSubscription()" is the only way to subscribe to MySQL publications. Is there any way to get this to work using the standard "this.subscribe()" function inside Template.onCreated()?

Relevant Meteor docs here: http://docs.meteor.com/#/full/Blaze-TemplateInstance-subscribe

Thanks

deejross avatar Oct 01 '15 17:10 deejross

That is correct, you must subscribe using the constructor new MysqlSubscription. Since this is not using this.subscribe(), you must stop the subscription manually in the Template.onDestroyed().

numtel avatar Oct 17 '15 15:10 numtel

what if the template is not destroyed? instead, the arguments it takes is changed by some reactive sources like sessions. I'm facing with a "tracker exception error subscrption failed" error when im trying to make MysqlSubscription in Template.onCreated autorun passing a param from FlowRouter.getQueryParam(which is reactive).

blitzlightnin avatar Nov 21 '15 21:11 blitzlightnin

I have the same problem using change() function. Sobetimes it work's and sobetimes I get the "Subscription failed" error.

danielgrabowski avatar Jan 12 '16 12:01 danielgrabowski

@danielgrabowski Can you post a link to a repo containing the minimum code necessary to reproduce the issue?

numtel avatar Jan 12 '16 13:01 numtel

As a response to @blitzlightnin - This is what I did for Template-Level Subscriptions:

Template.logEntries.created = function() {
  this.computation = Tracker.autorun(() => {
    if (this.logEntries) {
      this.logEntries.stop();
      this.logEntries = null;
    }
    var from = Session.get("logentries.from");
    var till = Session.get("logentries.till");
    this.logEntries = new MysqlSubscription('logEntries', {from: from, till: till});
  });
};

Template.logEntries.destroyed = function() {
  this.computation.stop();
  this.logEntries.stop();
};

Template.logEntries.helpers({
  logEntries: function () {
    Session.get("logentries.from");
    Session.get("logentries.till");
    return Template.instance().logEntries.reactive();
  }
});

Aur0r avatar Apr 14 '16 12:04 Aur0r