gpt4 book ai didi

javascript - 应用重启时 meteor 自动刷新

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:27 24 4
gpt4 key购买 nike

当服务器重新启动时,Meteor 会自动刷新所有已连接客户端的所有选项卡。我需要控制该功能,使其刷新速度变慢并通知正在发生的事情。

我在 livedata 包的源代码中找到了代码,但是有没有办法在不破解核心包的情况下控制它。

最佳答案

packages/reload/reload.js 中有一个私有(private) API 可以执行此操作。由于 API 是私有(private)的,因此它可能会发生变化,但它的工作原理如下:

例子:

if (Meteor.isClient) {

var firstTime = true;

function onMigrate (retry) {
if (firstTime) {
console.log("retrying migration in 3 seconds");
firstTime = false;
Meteor.setTimeout(function () {
retry();
}, 3000);
return false;
} else {
return [true];
}
}

Meteor._reload.onMigrate("someName", onMigrate);

// or Meteor._reload.onMigrate(onMigrate);

}

来自packages/reload/reload.js中的注释:

Packages that support migration should register themselves by calling this function. When it's time to migrate, callback will be called with one argument, the "retry function." If the package is ready to migrate, it should return [true, data], where data is its migration data, an arbitrary JSON value (or [true] if it has no migration data this time). If the package needs more time before it is ready to migrate, it should return false. Then, once it is ready to migrating again, it should call the retry function. The retry function will return immediately, but will schedule the migration to be retried, meaning that every package will be polled once again for its migration data. If they are all ready this time, then the migration will happen. name must be set if there is migration data.

关于javascript - 应用重启时 meteor 自动刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15053204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com