背景中的流星加载集合



我使用 iron:router 订阅钩子在 meteor.js 应用程序的每个页面中加载所需的数据(使用订阅管理器):

subscriptions: function() {
    return subman.subscribe("ElementsCurrentLang", Session.get('currentLang'), ['home']);
}

我还想在后台预加载其他订阅(当前页面中不需要所有订阅,但当前页面可能需要其中的一部分);我试图插入

globalSubs = {};
Meteor.subscribe("elementsCurrentLang", Session.get('currentLang'), function() {
    globalSubs.globalElements = true;
});
Meteor.subscribe("municipalitiesGlobal", Session.get('currentLang'), function() {
    globalSubs.globalMunicipalities = true;
});
Meteor.subscribe("culturalGoodsGlobal", Session.get('currentLang'), function() {
    globalSubs.globalCulturalGoods = true;
});

在单独的文件订阅中.js并添加了如下所示的测试,以避免重新下标到已加载的订阅:

subscriptions: function() {
    if (!globalSubs.globalElements) return subman.subscribe("neededElementsCurrentLang", Session.get('currentLang'), ['progetto']);
},

但这不起作用,因为全局订阅是在页面订阅之前加载的,而不是在后台加载的;

是否可以在后台加载 3 个全局订阅,避免应用程序等待它们加载(它必须仅等待当前路由的订阅钩子)?

    Router.configure({
  layoutTemplate: 'layout',
  waitOn: function(){ 
  return [Meteor.subscribe('posts'),Meteor.subscribe('colors'),Meteor.subscribe('ads')];},
  yieldTemplates:{
    'header': {to: 'header'},
    'menu': {to: 'menu'},
    'footer': {to:'footer'}
  }
});

这个怎么样。

最新更新