Reputation: 55029
Meteor automatically refreshes all tabs for all connected clients when the server restarts. I need to control that functionality so that it refreshes slower and gives notice of what's happening.
I found the code in the source in the livedata package, but is there some way to control it without hacking the core package.
Upvotes: 4
Views: 1317
Reputation: 1950
There is a private API in packages/reload/reload.js to do this. Since the API is private it might change, but here is how it works:
Example:
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);
}
From the comments in 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.
Upvotes: 2