Hot Code Push NodeJS

后端 未结 2 1827
礼貌的吻别
礼貌的吻别 2021-02-06 10:05

I\'ve been trying to figure out this \"Hot Code Push\" on Node.js. Basically, my main file (that is run when you type node app.js) consists of some settings, config

2条回答
  •  遇见更好的自我
    2021-02-06 10:34

    Meteor solves this problem by allowing modules to "register" themselves as part of the hot code push process.

    They implement this in their reload package:

    https://github.com/meteor/meteor/blob/master/packages/reload/reload.js#L105-L109

    I've seen that Meteor.reload API used in some plugins on GitHub, but they also use it in the session package:

    https://github.com/meteor/meteor/blob/master/packages/session/session.js#L103-L115

    if (Meteor._reload) {
      Meteor._reload.onMigrate('session', function () {
        return [true, {keys: Session.keys}];
      });
    
      (function () {
        var migrationData = Meteor._reload.migrationData('session');
        if (migrationData && migrationData.keys) {
          Session.keys = migrationData.keys;
        }
      })();
    }
    

    So basically, when the page/window loads, meteor runs a "migration", and it's up to the package to define the data/methods/etc. that get recomputed when a hot code push is made.

    It's also being used by their livedata package (search reload).

    Between refreshes they're saving the "state" using window.sessionStorage.

提交回复
热议问题