Open rosspeoples opened 9 years ago
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()
.
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).
I have the same problem using change() function. Sobetimes it work's and sobetimes I get the "Subscription failed" error.
@danielgrabowski Can you post a link to a repo containing the minimum code necessary to reproduce the issue?
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();
}
});
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