2015-03-12 06:48:00 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2015-05-22 04:58:22 +08:00
|
|
|
/*globals __resourceQuery */
|
2013-06-19 19:49:57 +08:00
|
|
|
if(module.hot) {
|
2015-05-22 04:58:22 +08:00
|
|
|
var hotPollInterval = +(__resourceQuery.substr(1)) || (10 * 60 * 1000);
|
2015-07-16 06:27:37 +08:00
|
|
|
|
2015-03-12 06:48:00 +08:00
|
|
|
function checkForUpdate(fromUpdate) {
|
2013-06-19 19:49:57 +08:00
|
|
|
if(module.hot.status() === "idle") {
|
2015-06-13 17:45:28 +08:00
|
|
|
module.hot.check(true).then(function(updatedModules) {
|
2015-03-12 06:48:00 +08:00
|
|
|
if(!updatedModules) {
|
|
|
|
if(fromUpdate) console.log("[HMR] Update applied.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require("./log-apply-result")(updatedModules, updatedModules);
|
|
|
|
checkForUpdate(true);
|
2015-06-13 17:45:28 +08:00
|
|
|
}).catch(function(err) {
|
2016-06-21 03:46:27 +08:00
|
|
|
var status = module.hot.status();
|
|
|
|
if(["abort", "fail"].indexOf(status) >= 0) {
|
2015-06-13 17:45:28 +08:00
|
|
|
console.warn("[HMR] Cannot apply update.");
|
|
|
|
console.warn("[HMR] " + err.stack || err.message);
|
|
|
|
console.warn("[HMR] You need to restart the application!");
|
|
|
|
} else {
|
|
|
|
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
|
|
|
}
|
2013-06-19 19:49:57 +08:00
|
|
|
});
|
|
|
|
}
|
2015-03-12 06:48:00 +08:00
|
|
|
}
|
|
|
|
setInterval(checkForUpdate, hotPollInterval);
|
|
|
|
} else {
|
|
|
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
|
|
|
}
|