什么时候是“空"?发布准备好了吗? [英] When is the "null" publish ready?

查看:66
本文介绍了什么时候是“空"?发布准备好了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在服务器上有以下代码:

Having the following code on the server:

Meteor.publish(null, function(){
    // Return some cursors.
})

将根据文档产生以下效果:记录集会自动发送到所有连接的客户端.

will according to the documentation have the following effect: the record set is automatically sent to all connected clients.

客户端如何判断该函数发布的所有文档是否都已收到?如果我改用订阅,它将为我提供一个准备好的回调,让我知道何时收到所有文件.这里的匹配方式是什么?还是当我的客户端代码开始执行时,客户端已经收到了文档?

How can I on the client side determine if all the documents published by this function has been received? If I would use a subscription instead, it would provide me with a ready callback, letting me know when all the documents been received. What's the matching way here? Or are the documents already received at the client when my client side code starts to execute?

推荐答案

恐怕没有办法为你上面提到的所谓的通用订阅准备好回调.只需看看流星代码的这部分,其中publishsubscription 逻辑在服务器上定义.为方便起见,我复制/粘贴以下代码:

I'm afraid there's no way to have a ready callback for so called universal subscriptions you mentioned above. Just have a look at this part of Meteor's code, where the publish and subscription logic is defined on the server. For convenience I'm copy/pasting the code below:

ready: function () {
  var self = this;
  if (self._isDeactivated())
    return;
  if (!self._subscriptionId)
    return;  // unnecessary but ignored for universal sub
  if (!self._ready) {
    self._session.sendReady([self._subscriptionId]);
    self._ready = true;
  }
}

_subscriptionId 仅提供给命名订阅,即您将使用 Meteor.subscribe 方法手动定义的订阅.null 发布函数对应的订阅,没有自己的_subscriptionId,所以从上面的代码可以看出,服务器不是事件试图发送 _subscriptionIdcode>ready 消息给客户端.

The _subscriptionId is only given to named subscriptions, which are those that you would manually define using Meteor.subscribe method. The subscriptions corresponding to null publish functions, doesn't have their own _subscriptionId, so as you can see from the code above, the server is not event trying to send the ready message to the client.

这篇关于什么时候是“空"?发布准备好了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆