Meteor recently introduced template subscription capabilities. You can now call this.subscribe
from within a Temeplate.xyz.onCreated
call and the helper {{#if Template.subscriptionsReady}} will only be true once the subscriptions have gotten ready from the server.
Unfortunately this does not seem to be obviously compatible with subs-manager or subs-Cache
How woudl you use subs-Cache in-place of this.subscribe such that the subscription ids made by the subsciptions manager make it into _subscriptionHandles and _allSubsReady part of this.subscribe? Or otherwise asked, how do you get {{#if Template.subscriptionsReady}} and the function Template.instance().subscriptionsReady() to depend on Template subscriptions made with subs-Cache.
Example code that does not work:
# in some top level file
share.subsCache = new SubsCache(
expireAter: 5
cacheLimit: 10
)
#in a template file
Template.entryRevisionInfo.onCreated ->
share.subsCache.subscribe('somePub')
The next (unreleased) version of meteor has a connection
option to TemplateInstance#subscribe
, and I would expect that you would be able to pass a subscription manager as the "connection."
Sacha Greif wrote a solution in the Telescope app. I've tried to extract the parts that are significant to a basic implementation below. As far as I understand it relies on explicitly setting the ready status of the template... setting it reactively when the subscription is ready:
subsManager = new SubsManager();
Template.templatename.onCreated(function () {
var instance = this;
instance.ready = new ReactiveVar(false);
subscription = subsManager.subscribe('yourCollection')
instance.autorun(function () {
if (subscription.ready()) { //reactive
instance.ready.set(true);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With