javascript – 应用程序重启时Meteor自动刷新

当服务器重新启动时,Meteor会自动刷新所有连接的客户端的所有选项卡.我需要控制该功能,以便更快地刷新并通知正在发生的事情.

我在livingata包中找到了源代码,但是有一些方法可以控制它而不会破坏核心包.

最佳答案 在packages / reload / reload.js中有一个私有API来执行此操作.由于API是私有的,它可能会改变,但这是它的工作原理:

例:

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.

点赞