删除Meteor中未登录用户的加载模板

时间:2015-02-18 20:32:38

标签: javascript meteor

我在我的应用程序上使用pub / sub,但是当没有用户登录时,订阅会按照waitOn方法加载loadingTemplate

 loadingTemplate: 'loading',
      waitOn: function(){
          return Meteor.subscribe('lists');
     }

我希望以下空格键能够启动,但waitOn方法阻止了它

   {{#unless currentUser}}
        <div class="alert alert-error">
        log in to access your kaleo
        </div>
        <h2 class='login-welcome'>sign in above to access your kaleo</h2>
    {{/unless}}

1 个答案:

答案 0 :(得分:1)

如果您的发布功能在用户未登录时失败,则通常最适合return this.ready()。例如:

Meteor.publish('lists', function() {
  if (!this.userId)
    return this.ready();

  return Lists.find({owner: this.userId});
});

这应该可以解决装载模板卡住的直接问题。但从技术上讲,waitOn仍将运行,并且在生产环境中延迟可能更为明显。你可以尝试这样的事情:

waitOn: function(){
  if (Meteor.loggingIn() || Meteor.userId())
    return Meteor.subscribe('lists');
}

当用户未登录时,应避免订阅,但我自己没有对其进行测试。