Introduce HMR runtime

Summary:
public

Add a very simple runtime for self-accepting modules. The API is the same one as Webpacks's one for now.
The new infra will be end-to-end tested on a follow up diff.

Reviewed By: vjeux

Differential Revision: D2789428

fb-gh-sync-id: c39524814d53c6e4ec9d9d011081ea81089b00b6
This commit is contained in:
Martín Bigio 2015-12-28 16:43:16 -08:00 committed by facebook-github-bot-6
parent ac9c3c548d
commit 245065be87
1 changed files with 31 additions and 0 deletions

View File

@ -10,6 +10,17 @@
isInitialized: false,
hasError: false,
};
if (__DEV__) { // HMR
Object.assign(modules[id].module, {
hot: {
acceptCallback: null,
accept: function(callback) {
this.acceptCallback = callback;
}
}
});
}
}
function require(id) {
@ -82,4 +93,24 @@
global.__d = define;
global.require = require;
if (__DEV__) { // HMR
function accept(id, factory) {
var mod = modules[id];
if (mod.module.hot.acceptCallback) {
mod.factory = factory;
mod.isInitialized = false;
require(id);
mod.hot.acceptCallback();
} else {
console.log(
'[HMR] Module `' + id + '` cannot be accepted. ' +
'Please reload bundle to get the updates.'
);
}
}
global.__accept = accept;
}
})(this);