简体   繁体   English

Meteor.status()不是反应性数据源吗?

[英]Meteor.status() is not a reactive data source?

We're trying to do the following to show a connection status on our app: 我们正在尝试执行以下操作以在我们的应用程序上显示连接状态:

this.helpers({
    userBlock: () => {
        //...
        return {
            name: name,
            connectionStatus: Meteor.status().connected
        }
    }
});

However the helper doesn't re run after the server is disconnected. 但是,断开服务器连接后,该帮助程序不会重新运行。 Outputting Meteor.status().connected variable directly into the template, both via $scope and controller reference doesn't see its value updating either. 通过$ scope和controller引用将Meteor.status().connected变量直接输出到模板中,也看不到其值更新。 Any ideas on how we can get the helper to re run with Meteor.status().connected change? 关于如何获取与Meteor.status().connected更改一起运行的帮助程序的任何想法?

This is how I implemented and it works as expected. 这就是我的实现方式,并且按预期运行。 When server is down, the template renders "Disconnected" message and it disappears when server is back again. 当服务器关闭时,该模板将呈现“ Disconnected”(断开连接)消息,当服务器再次返回时,它将消失。

var SHOW_CONNECTION_ISSUE_KEY = 'showConnectionIssue';
Session.setDefault(SHOW_CONNECTION_ISSUE_KEY, false);

Meteor.startup(function () {

   // Only show the connection error box if it has been 5 seconds since
   // the app started
   setTimeout(function () {
       // Show the connection error box
       Session.set(SHOW_CONNECTION_ISSUE_KEY, true);
   }, 5000);
});

Template.header.helpers({
   connected: function() {
       if (Session.get(SHOW_CONNECTION_ISSUE_KEY)) {
           return Meteor.status().connected; 
       } else {
           return true;
       }
}});

and in template: 并在模板中:

{{#unless connected}}
        <div class="alert alert-danger">
            Disconnected
        </div>
{{/unless}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM