fixed some bugs #26

This commit is contained in:
Tobias Koppers 2013-06-19 16:41:57 +02:00
parent d8fc8472f6
commit 2e5fc25fa7
3 changed files with 19 additions and 7 deletions

View File

@ -177,12 +177,14 @@ var hotInitCode = function() {
function hotUpdateDownloaded() {
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();
while(queue.length > 0) {
var moduleId = queue.pop();
var module = installedModules[moduleId];
if(module.hot._selfAccepted)
if(!module || module.hot._selfAccepted)
continue;
if(module.hot._selfDeclined) {
hotSetStatus("abort");
@ -322,8 +324,9 @@ var hotInitCode = function() {
var hotWaitingFilesMap = {};
var hotCallback;
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(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"));
hotSetStatus("check");
@ -346,7 +349,7 @@ var hotInitCode = function() {
hotWaitingFilesMap = {};
hotSetStatus("prepare");
hotCallback = callback || function(err) { if(err) throw err };
hotCallback = callback;
hotUpdate = {};
var hash = hotCurrentHash;
/*foreachInstalledChunks*/ {
@ -373,7 +376,7 @@ var hotInitCode = function() {
var outdatedModules = hotUpdateOutdatedModules;
var outdatedDependencies = hotUpdateOutdatedDependencies;
var outdatedSelfAcceptedModules = outdatedModules.filter(function(moduleId) {
return installedModules[moduleId].hot._selfAccepted;
return installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted;
});
hotSetStatus("dispose");
@ -381,14 +384,15 @@ var hotInitCode = function() {
outdatedModules.forEach(function(moduleId) {
var data = {};
var module = installedModules[moduleId];
if(!module) return;
module.hot._disposeHandlers.forEach(function(cb) {
cb(data);
});
oldModulesData[moduleId] = data;
return
}, this);
outdatedModules.forEach(function(moduleId) {
var module = installedModules[moduleId];
if(!module) return;
delete installedModules[moduleId];
module.children.forEach(function(child) {
child = installedModules[child];

View File

@ -0,0 +1,4 @@
// This file can update, because it accept itself.
// A dispose handler removes the old <style> element.
require("bundle!./style2.js");

View File

@ -38,7 +38,7 @@ window.onload = function() {
require("./style.js");
require("bundle!./style2.js");
require("./applyStyle2");
if(module.hot) {
@ -54,5 +54,9 @@ window.onload = function() {
document.body.appendChild(element2);
});
module.hot.accept("./applyStyle2", function() {
require("./applyStyle2");
});
}
};