mirror of https://github.com/webpack/webpack.git
fixed some bugs #26
This commit is contained in:
parent
d8fc8472f6
commit
2e5fc25fa7
|
@ -177,12 +177,14 @@ var hotInitCode = function() {
|
||||||
|
|
||||||
function hotUpdateDownloaded() {
|
function hotUpdateDownloaded() {
|
||||||
var outdatedDependencies = hotUpdateOutdatedDependencies = {};
|
var outdatedDependencies = hotUpdateOutdatedDependencies = {};
|
||||||
var outdatedModules = hotUpdateOutdatedModules = Object.keys(hotUpdate).slice();
|
var outdatedModules = hotUpdateOutdatedModules = Object.keys(hotUpdate).map(function(id) {
|
||||||
|
return +id;
|
||||||
|
});
|
||||||
var queue = outdatedModules.slice();
|
var queue = outdatedModules.slice();
|
||||||
while(queue.length > 0) {
|
while(queue.length > 0) {
|
||||||
var moduleId = queue.pop();
|
var moduleId = queue.pop();
|
||||||
var module = installedModules[moduleId];
|
var module = installedModules[moduleId];
|
||||||
if(module.hot._selfAccepted)
|
if(!module || module.hot._selfAccepted)
|
||||||
continue;
|
continue;
|
||||||
if(module.hot._selfDeclined) {
|
if(module.hot._selfDeclined) {
|
||||||
hotSetStatus("abort");
|
hotSetStatus("abort");
|
||||||
|
@ -322,8 +324,9 @@ var hotInitCode = function() {
|
||||||
var hotWaitingFilesMap = {};
|
var hotWaitingFilesMap = {};
|
||||||
var hotCallback;
|
var hotCallback;
|
||||||
function hotCheck(callback) {
|
function hotCheck(callback) {
|
||||||
|
callback = callback || function(err) { if(err) throw err };
|
||||||
if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
|
if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
|
||||||
if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Object.keys)
|
if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Array.prototype.map || !Object.keys)
|
||||||
return callback(new Error("No browser support"));
|
return callback(new Error("No browser support"));
|
||||||
hotSetStatus("check");
|
hotSetStatus("check");
|
||||||
|
|
||||||
|
@ -346,7 +349,7 @@ var hotInitCode = function() {
|
||||||
|
|
||||||
hotWaitingFilesMap = {};
|
hotWaitingFilesMap = {};
|
||||||
hotSetStatus("prepare");
|
hotSetStatus("prepare");
|
||||||
hotCallback = callback || function(err) { if(err) throw err };
|
hotCallback = callback;
|
||||||
hotUpdate = {};
|
hotUpdate = {};
|
||||||
var hash = hotCurrentHash;
|
var hash = hotCurrentHash;
|
||||||
/*foreachInstalledChunks*/ {
|
/*foreachInstalledChunks*/ {
|
||||||
|
@ -373,7 +376,7 @@ var hotInitCode = function() {
|
||||||
var outdatedModules = hotUpdateOutdatedModules;
|
var outdatedModules = hotUpdateOutdatedModules;
|
||||||
var outdatedDependencies = hotUpdateOutdatedDependencies;
|
var outdatedDependencies = hotUpdateOutdatedDependencies;
|
||||||
var outdatedSelfAcceptedModules = outdatedModules.filter(function(moduleId) {
|
var outdatedSelfAcceptedModules = outdatedModules.filter(function(moduleId) {
|
||||||
return installedModules[moduleId].hot._selfAccepted;
|
return installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted;
|
||||||
});
|
});
|
||||||
|
|
||||||
hotSetStatus("dispose");
|
hotSetStatus("dispose");
|
||||||
|
@ -381,14 +384,15 @@ var hotInitCode = function() {
|
||||||
outdatedModules.forEach(function(moduleId) {
|
outdatedModules.forEach(function(moduleId) {
|
||||||
var data = {};
|
var data = {};
|
||||||
var module = installedModules[moduleId];
|
var module = installedModules[moduleId];
|
||||||
|
if(!module) return;
|
||||||
module.hot._disposeHandlers.forEach(function(cb) {
|
module.hot._disposeHandlers.forEach(function(cb) {
|
||||||
cb(data);
|
cb(data);
|
||||||
});
|
});
|
||||||
oldModulesData[moduleId] = data;
|
oldModulesData[moduleId] = data;
|
||||||
return
|
|
||||||
}, this);
|
}, this);
|
||||||
outdatedModules.forEach(function(moduleId) {
|
outdatedModules.forEach(function(moduleId) {
|
||||||
var module = installedModules[moduleId];
|
var module = installedModules[moduleId];
|
||||||
|
if(!module) return;
|
||||||
delete installedModules[moduleId];
|
delete installedModules[moduleId];
|
||||||
module.children.forEach(function(child) {
|
module.children.forEach(function(child) {
|
||||||
child = installedModules[child];
|
child = installedModules[child];
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
// This file can update, because it accept itself.
|
||||||
|
// A dispose handler removes the old <style> element.
|
||||||
|
|
||||||
|
require("bundle!./style2.js");
|
|
@ -38,7 +38,7 @@ window.onload = function() {
|
||||||
|
|
||||||
require("./style.js");
|
require("./style.js");
|
||||||
|
|
||||||
require("bundle!./style2.js");
|
require("./applyStyle2");
|
||||||
|
|
||||||
if(module.hot) {
|
if(module.hot) {
|
||||||
|
|
||||||
|
@ -54,5 +54,9 @@ window.onload = function() {
|
||||||
document.body.appendChild(element2);
|
document.body.appendChild(element2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.hot.accept("./applyStyle2", function() {
|
||||||
|
require("./applyStyle2");
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue