From 5803dfbf2f241a3c2e6c0cd088f941de634166ca Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Thu, 21 Nov 2013 16:31:49 -0800 Subject: [PATCH 1/2] Comments and safety belts from glasser's review. --- packages/autoupdate/autoupdate_client.js | 10 +++++----- packages/autoupdate/autoupdate_server.js | 21 ++++++++++++++------- packages/livedata/livedata_connection.js | 6 +++--- packages/livedata/stream_server.js | 8 ++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/packages/autoupdate/autoupdate_client.js b/packages/autoupdate/autoupdate_client.js index 2216e80c3f..6a0d6386cb 100644 --- a/packages/autoupdate/autoupdate_client.js +++ b/packages/autoupdate/autoupdate_client.js @@ -1,16 +1,16 @@ // Subscribe to the `meteor_autoupdate_clientVersions` collection, // which contains the set of acceptable client versions. // -// A "hard code push" occurs when the current client version is not in +// A "hard code push" occurs when the running client version is not in // the set of acceptable client versions (or the server updates the -// collection, and the current client version is no longer in the -// set). +// collection, there is a published client version marked `current` and +// the running client version is no longer in the set). // // When the `reload` package is loaded, a hard code push causes // the browser to reload, so that it will load the latest client // version from the server. // -// A "soft code push" represents the situation when the current client +// A "soft code push" represents the situation when the running client // version is in the set of acceptable versions, but there is a newer // version available on the server. // @@ -24,7 +24,7 @@ // The client version of the client code currently running in the // browser. -var autoUpdateVersion = __meteor_runtime_config__.autoUpdateVersion; +var autoUpdateVersion = __meteor_runtime_config__.autoUpdateVersion || "unknown"; // The collection of acceptable client versions. diff --git a/packages/autoupdate/autoupdate_server.js b/packages/autoupdate/autoupdate_server.js index 1d0031e76d..648ce0d553 100644 --- a/packages/autoupdate/autoupdate_server.js +++ b/packages/autoupdate/autoupdate_server.js @@ -45,10 +45,12 @@ AutoUpdate = {}; AutoUpdate.autoUpdateVersion = null; Meteor.startup(function () { + // Allow people to override AutoUpdate.autoUpdateVersion before + // startup. Tests do this. if (AutoUpdate.autoUpdateVersion === null) AutoUpdate.autoUpdateVersion = process.env.AUTOUPDATE_VERSION || - process.env.SERVER_ID || + process.env.SERVER_ID || // XXX COMPAT 0.6.6 WebApp.clientHash; // Make autoUpdateVersion available on the client. @@ -63,12 +65,17 @@ Meteor.publish( // Using `autoUpdateVersion` here is safe because we can't get a // subscription before webapp starts listening, and it doesn't do // that until the startup hooks have run. - self.added( - "meteor_autoupdate_clientVersions", - AutoUpdate.autoUpdateVersion, - {current: true} - ); - self.ready(); + if (AutoUpdate.autoUpdateVersion) { + self.added( + "meteor_autoupdate_clientVersions", + AutoUpdate.autoUpdateVersion, + {current: true} + ); + self.ready(); + } else { + // huh? shouldn't happen. Just error the sub. + self.error(new Meteor.Error(500, "AutoUpdate.autoUpdateVersion not set")); + } }, {is_auto: true} ); diff --git a/packages/livedata/livedata_connection.js b/packages/livedata/livedata_connection.js index 15b37d1b96..81f05de24c 100644 --- a/packages/livedata/livedata_connection.js +++ b/packages/livedata/livedata_connection.js @@ -181,9 +181,9 @@ var Connection = function (url, options) { } if (msg === null || !msg.msg) { - // DEPRECATED. ignore the old welcome message for back compat. - // Remove this 'if' once the server stops sending welcome messages - // (stream_server.js). + // XXX COMPAT WITH 0.6.6. ignore the old welcome message for back + // compat. Remove this 'if' once the server stops sending welcome + // messages (stream_server.js). if (! (msg && msg.server_id)) Meteor._debug("discarding invalid livedata message", msg); return; diff --git a/packages/livedata/stream_server.js b/packages/livedata/stream_server.js index 160d11e9e8..c675cb9e57 100644 --- a/packages/livedata/stream_server.js +++ b/packages/livedata/stream_server.js @@ -65,10 +65,10 @@ StreamServer = function () { }); self.open_sockets.push(socket); - // DEPRECATED. Send the old style welcome message, which will force - // old clients to reload. Remove this once we're not concerned about - // people upgrading from a pre-0.6.7 release. Also, remove the - // clause in the client that ignores the welcome message + // XXX COMPAT WITH 0.6.6. Send the old style welcome message, which + // will force old clients to reload. Remove this once we're not + // concerned about people upgrading from a pre-0.6.7 release. Also, + // remove the clause in the client that ignores the welcome message // (livedata_connection.js) socket.send(JSON.stringify({server_id: "0"})); From f25b733bc6159d3f054223660cf17e95324e8ceb Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Thu, 21 Nov 2013 16:34:07 -0800 Subject: [PATCH 2/2] Change AutoUpdate symbol name to be one word not two. perl -pi -e 's/AutoUpdate/Autoupdate/g' **/*.{js,md} perl -pi -e 's/autoUpdate/autoupdate/g' **/*.{js,md} --- packages/appcache/appcache-server.js | 2 +- packages/autoupdate/QA.md | 4 ++-- packages/autoupdate/autoupdate_client.js | 12 ++++++------ packages/autoupdate/autoupdate_server.js | 22 +++++++++++----------- packages/autoupdate/package.js | 2 +- packages/test-in-browser/autoupdate.js | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/appcache/appcache-server.js b/packages/appcache/appcache-server.js index 936be30359..d503440381 100644 --- a/packages/appcache/appcache-server.js +++ b/packages/appcache/appcache-server.js @@ -103,7 +103,7 @@ WebApp.connectHandlers.use(function(req, res, next) { // reload again trying to get the new code. if (Package.autoupdate) { - var version = Package.autoupdate.AutoUpdate.autoUpdateVersion; + var version = Package.autoupdate.Autoupdate.autoupdateVersion; if (version !== WebApp.clientHash) manifest += "# " + version + "\n"; } diff --git a/packages/autoupdate/QA.md b/packages/autoupdate/QA.md index 189353ec32..3e26c4a40b 100644 --- a/packages/autoupdate/QA.md +++ b/packages/autoupdate/QA.md @@ -59,7 +59,7 @@ so it doesn't wait for new files to download before displaying the web page. -## AutoUpdate.newClientAvailable +## Autoupdate.newClientAvailable Undo previous changes made, such as by using `git checkout .` Reload the client, which will cause the browser to stop using the app cache. @@ -75,7 +75,7 @@ see the variable without having the client also reload. Add to leaderboard.js: - Template.leaderboard.available = AutoUpdate.newClientAvailable; + Template.leaderboard.available = Autoupdate.newClientAvailable; And add `{{available}}` to the leaderboard template in leaderboard.html. diff --git a/packages/autoupdate/autoupdate_client.js b/packages/autoupdate/autoupdate_client.js index 6a0d6386cb..34e90184f9 100644 --- a/packages/autoupdate/autoupdate_client.js +++ b/packages/autoupdate/autoupdate_client.js @@ -14,7 +14,7 @@ // version is in the set of acceptable versions, but there is a newer // version available on the server. // -// `AutoUpdate.newClientAvailable` is a reactive data source which +// `Autoupdate.newClientAvailable` is a reactive data source which // becomes `true` if there is a new version of the client is available on // the server. // @@ -24,20 +24,20 @@ // The client version of the client code currently running in the // browser. -var autoUpdateVersion = __meteor_runtime_config__.autoUpdateVersion || "unknown"; +var autoupdateVersion = __meteor_runtime_config__.autoupdateVersion || "unknown"; // The collection of acceptable client versions. var ClientVersions = new Meteor.Collection("meteor_autoupdate_clientVersions"); -AutoUpdate = {}; +Autoupdate = {}; -AutoUpdate.newClientAvailable = function () { +Autoupdate.newClientAvailable = function () { return !! ClientVersions.findOne( {$and: [ {current: true}, - {_id: {$ne: autoUpdateVersion}} + {_id: {$ne: autoupdateVersion}} ]} ); }; @@ -51,7 +51,7 @@ Meteor.subscribe("meteor_autoupdate_clientVersions", { if (Package.reload) { Deps.autorun(function (computation) { if (ClientVersions.findOne({current: true}) && - (! ClientVersions.findOne({_id: autoUpdateVersion}))) { + (! ClientVersions.findOne({_id: autoupdateVersion}))) { computation.stop(); Package.reload.Reload._reload(); } diff --git a/packages/autoupdate/autoupdate_server.js b/packages/autoupdate/autoupdate_server.js index 648ce0d553..9bf2a8dfd5 100644 --- a/packages/autoupdate/autoupdate_server.js +++ b/packages/autoupdate/autoupdate_server.js @@ -35,26 +35,26 @@ // client version. Developers can easily experiment with different // versioning and updating models by forking this package. -AutoUpdate = {}; +Autoupdate = {}; // The client hash includes __meteor_runtime_config__, so wait until // all packages have loaded and have had a chance to populate the // runtime config before using the client hash as our default auto // update version id. -AutoUpdate.autoUpdateVersion = null; +Autoupdate.autoupdateVersion = null; Meteor.startup(function () { - // Allow people to override AutoUpdate.autoUpdateVersion before + // Allow people to override Autoupdate.autoupdateVersion before // startup. Tests do this. - if (AutoUpdate.autoUpdateVersion === null) - AutoUpdate.autoUpdateVersion = + if (Autoupdate.autoupdateVersion === null) + Autoupdate.autoupdateVersion = process.env.AUTOUPDATE_VERSION || process.env.SERVER_ID || // XXX COMPAT 0.6.6 WebApp.clientHash; - // Make autoUpdateVersion available on the client. - __meteor_runtime_config__.autoUpdateVersion = AutoUpdate.autoUpdateVersion; + // Make autoupdateVersion available on the client. + __meteor_runtime_config__.autoupdateVersion = Autoupdate.autoupdateVersion; }); @@ -62,19 +62,19 @@ Meteor.publish( "meteor_autoupdate_clientVersions", function () { var self = this; - // Using `autoUpdateVersion` here is safe because we can't get a + // Using `autoupdateVersion` here is safe because we can't get a // subscription before webapp starts listening, and it doesn't do // that until the startup hooks have run. - if (AutoUpdate.autoUpdateVersion) { + if (Autoupdate.autoupdateVersion) { self.added( "meteor_autoupdate_clientVersions", - AutoUpdate.autoUpdateVersion, + Autoupdate.autoupdateVersion, {current: true} ); self.ready(); } else { // huh? shouldn't happen. Just error the sub. - self.error(new Meteor.Error(500, "AutoUpdate.autoUpdateVersion not set")); + self.error(new Meteor.Error(500, "Autoupdate.autoupdateVersion not set")); } }, {is_auto: true} diff --git a/packages/autoupdate/package.js b/packages/autoupdate/package.js index c7f04a279c..994a125f0c 100644 --- a/packages/autoupdate/package.js +++ b/packages/autoupdate/package.js @@ -7,7 +7,7 @@ Package.on_use(function (api) { api.use(['livedata', 'mongo-livedata'], ['client', 'server']); api.use('reload', 'client', {weak: true}); - api.export('AutoUpdate'); + api.export('Autoupdate'); api.add_files('autoupdate_server.js', 'server'); api.add_files('autoupdate_client.js', 'client'); }); diff --git a/packages/test-in-browser/autoupdate.js b/packages/test-in-browser/autoupdate.js index b97d27fd4d..9e6c14a075 100644 --- a/packages/test-in-browser/autoupdate.js +++ b/packages/test-in-browser/autoupdate.js @@ -4,4 +4,4 @@ // different value when the server restarts accomplishes this. if (Package.autoupdate) - Package.autoupdate.AutoUpdate.autoUpdateVersion = Random.id(); + Package.autoupdate.Autoupdate.autoupdateVersion = Random.id();