当我运行 Meteor.disconnect() 然后 Meteor.reconnect() 时,Meteor 会清除 minimongo,我该如何防止这种情况发生? [英] When I run Meteor.disconnect() and then Meteor.reconnect(), Meteor clears minimongo, how can I prevent this?

查看:57
本文介绍了当我运行 Meteor.disconnect() 然后 Meteor.reconnect() 时,Meteor 会清除 minimongo,我该如何防止这种情况发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用中使用了快速渲染,因此应用需要的所有数据都随应用本身一起发送.我们没有使用任何 Meteor.subscribe 调用,因为 minimongo 是由快速渲染填充的.

We are using fast render in our app, so all the data the app needs is sent down with the app itself. We are not using any Meteor.subscribe calls since minimongo is populated by fast render.

渲染后我们运行 Meteor.disconnect()

Once rendered we run Meteor.disconnect()

在未来的某个时候,我们想重新连接以调用特定方法,但是当我们重新连接时,minimongo 被清除.

At some point in the future we want to reconnect to call a specific method, but when we reconnect, minimongo gets cleared.

我们如何防止 Meteor 在重新连接时清除 minimongo 中的所有文档?

How can we prevent Meteor from clearing all documents in minimongo upon reconnect?

推荐答案

我怀疑实际上是快速渲染导致了您的问题.检查 Meteor.disconnect()...

I suspect that it's actually fast render that is causing your problem. Checking the meteor docs for Meteor.disconnect()...

调用此方法可断开与服务器的连接并停止所有实时数据更新.当客户端断开连接时,它不会接收到集合的更新,方法调用将排队直到重新建立连接,并且热代码推送将被禁用.

Call this method to disconnect from the server and stop all live data updates. While the client is disconnected it will not receive updates to collections, method calls will be queued until the connection is reestablished, and hot code push will be disabled.

调用 Meteor.reconnect 重新建立连接并恢复数据传输.

Call Meteor.reconnect to reestablish the connection and resume data transfer.

当不需要实时更新时,这可用于节省移动设备的电池电量.

This can be used to save battery on mobile devices when real time updates are not required.

这意味着您的客户端数据永远不会被删除,否则您无法在重新连接时恢复数据传输".这也意味着他们使用此方法的主要预期用例之一(例如用于在不需要实时更新时为移动设备节省电池")实际上将不起作用.

This implies that your client data is never deleted, otherwise you could not "resume data transfer" upon reconnection. It also would mean that one of their primary intended use cases for this method (e.g. "used to save battery on mobile devices when real time updates are not required") would not actually work.

为了绝对确定,我检查了 流星源 以查看断开连接时会发生什么,并将连接状态变量设置为 false,清除 连接和心跳计时器,并取消任何挂起的meteor方法调用.

Just to be absolutely sure, I checked the meteor source to see what happens on a disconnect and all it does it set a connection state var to false, clear the connection and heartbeat timers, and cancels any pending meteor method calls.

类似地,Meteor.reconnect() 只需将连接状态 var 设置回 true,重新建立连接和心跳计时器,重新建立任何订阅(以便可以获取新数据...此操作不会删除客户端数据),并调用任何排队的流星方法调用.

Similarly, Meteor.reconnect() simply set the connection state var back to true, re-establishes the connection and hearbeat timers, re-establishes any subscriptions (so that new data can be acquired...this action does not delete client data), and calls any queued up meteor method calls.

阅读更多关于渲染工作速度有多快,我知道做了很多黑客攻击是为了让它真正发挥作用.跳出来给我的主要黑客是fake ready"hack 欺骗客户端在实际订阅准备好之前认为订阅已经准备好(因为数据是在初始页面加载时发送给客户端的).

After reading more about how fast render works, I understand that a lot of hacking was done to get it to actually work. The main hack that jumped out to me is the "fake ready" hack which tricks the client to thinking the subscription is ready before the actual subscription is ready (since the data was sent to the client on the initial page load).

由于您的应用程序中没有订阅,并且 Meteor.reconnect() 不会导致您的页面重新加载,我想知道客户端是否从未执行任何操作,因为它从未收到另一个 <代码>就绪消息.或者可能因为 Meteor 不知道任何订阅(因为快速渲染绕过meteor 来传输数据),它会清除客户端 minimongo 缓存,以便在启动新订阅时处于良好状态.或者,可能还有其他与快速渲染有关的因素.

Since you have no subscriptions in your app and a Meteor.reconnect() does not cause your page to reload, I'm wondering if the client is never doing anything because it never receives another ready message. Or maybe since Meteor isn't aware of any subscriptions (since fast render bypasses meteor to transport data), is clears the client minimongo cache so its in a good state if a new subscription is started. Or, there could be something else about fast render that is getting in the way.

长话短说,我很确定 Meteor.disconnect()Meteor.reconnet() 对您的客户端 minimongo 数据没有影响文档、来源,并基于我离线测试我的流星应用程序的经验.

Long story short, I'm quite certain that Meteor.disconnect() and Meteor.reconnet() have no impact on your client minimongo data based upon reviewing the documentation, the source, and based upon my experience of testing my meteor apps offline.

我可以 Meteor.reconnect() 不删除数据,因为我在生产中有一个 Meteor 应用程序,如果它检测到它会继续调用 Meteor.reconnect()已失去连接(例如,计算机离线、网络中断等).

I can Meteor.reconnect() does not delete data as I have a meteor app in production that continues to call Meteor.reconnect() if it detects that it has lost a connection (e.g. the computer goes offline, network outage, etc.).

希望这个冗长的答案可以帮助您跟踪应用程序的运行情况.

Hopefully this long winded answer helps you track down what's going on with your app.

这篇关于当我运行 Meteor.disconnect() 然后 Meteor.reconnect() 时,Meteor 会清除 minimongo,我该如何防止这种情况发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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