Skip to content

Commit 152c173

Browse files
committed
don't use es5 stuff in hmr code
1 parent 7662dba commit 152c173

1 file changed

Lines changed: 51 additions & 39 deletions

File tree

‎lib/HotModuleReplacementPlugin.js‎

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,14 @@ var hotInitCode = function() {
306306
function hotCheck(callback) {
307307
callback = callback || function(err) { if(err) throw err };
308308
if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
309-
if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Array.prototype.map || !Object.keys)
309+
if(typeof XMLHttpRequest === "undefined")
310310
return callback(new Error("No browser support"));
311311
hotSetStatus("check");
312312

313313
try {
314314
var request = new XMLHttpRequest();
315315
var chunkId = 0;
316-
request.open("GET", modules.c + $hotChunkFilename$, true);
316+
request.open("HEAD", modules.c + $hotChunkFilename$, true);
317317
request.send(null);
318318
} catch(err) {
319319
return callback(err);
@@ -331,7 +331,6 @@ var hotInitCode = function() {
331331
hotSetStatus("prepare");
332332
hotCallback = callback;
333333
hotUpdate = {};
334-
var hash = hotCurrentHash;
335334
/*foreachInstalledChunks*/ {
336335
hotDownloadUpdateChunk(chunkId);
337336
}
@@ -359,9 +358,10 @@ var hotInitCode = function() {
359358
if(hotApplyOnUpdate) {
360359
hotApply(callback);
361360
} else {
362-
var outdatedModules = Object.keys(hotUpdate).map(function(id) {
363-
return +id;
364-
});
361+
var outdatedModules = [];
362+
for(var id in hotUpdate) {
363+
outdatedModules.push(+id);
364+
}
365365
callback(null, outdatedModules);
366366
}
367367
}
@@ -370,9 +370,10 @@ var hotInitCode = function() {
370370
callback = callback || function(err) { if(err) throw err };
371371
if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status");
372372
var outdatedDependencies = {};
373-
var outdatedModules = Object.keys(hotUpdate).map(function(id) {
374-
return +id;
375-
});
373+
var outdatedModules = [];
374+
for(var id in hotUpdate) {
375+
outdatedModules.push(+id);
376+
}
376377
var queue = outdatedModules.slice();
377378
while(queue.length > 0) {
378379
var moduleId = queue.pop();
@@ -407,79 +408,90 @@ var hotInitCode = function() {
407408
}
408409
}
409410

410-
var outdatedSelfAcceptedModules = outdatedModules.filter(function(moduleId) {
411-
return installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted;
412-
});
411+
var outdatedSelfAcceptedModules = [];
412+
for(var i = 0; i < outdatedModules.length; i++) {
413+
var moduleId = outdatedModules[i];
414+
if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted)
415+
outdatedSelfAcceptedModules.push(moduleId);
416+
}
413417

414418
hotSetStatus("dispose");
415419
hotCurrentModuleData = {};
416-
outdatedModules.forEach(function(moduleId) {
420+
for(var i = 0; i < outdatedModules.length; i++) {
421+
var moduleId = outdatedModules[i];
417422
var data = {};
418423
var module = installedModules[moduleId];
419-
if(!module) return;
420-
module.hot._disposeHandlers.forEach(function(cb) {
424+
if(!module) continue;
425+
var disposeHandlers = module.hot._disposeHandlers;
426+
for(var j = 0; j < disposeHandlers.length; j++) {
427+
var cb = disposeHandlers[j]
421428
cb(data);
422-
});
429+
}
423430
hotCurrentModuleData[moduleId] = data;
424-
}, this);
425-
outdatedModules.forEach(function(moduleId) {
431+
}
432+
for(var i = 0; i < outdatedModules.length; i++) {
433+
var moduleId = outdatedModules[i];
426434
var module = installedModules[moduleId];
427-
if(!module) return;
435+
if(!module) continue;
428436
delete installedModules[moduleId];
429-
module.children.forEach(function(child) {
430-
child = installedModules[child];
431-
if(!child) return;
437+
for(var j = 0; j < module.children.length; j++) {
438+
var child = installedModules[module.children[j]];
439+
if(!child) continue;
432440
var idx = child.parents.indexOf(moduleId);
433441
if(idx >= 0) child.parents.splice(idx, 1);
434-
}, this);
435-
});
436-
Object.keys(outdatedDependencies).forEach(function(moduleId) {
442+
}
443+
}
444+
for(var moduleId in outdatedDependencies) {
437445
var module = installedModules[moduleId];
438446
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
439-
moduleOutdatedDependencies.forEach(function(dependency) {
447+
for(var j = 0; j < moduleOutdatedDependencies.length; j++) {
448+
var dependency = moduleOutdatedDependencies[j];
440449
var idx = module.children.indexOf(dependency);
441450
if(idx >= 0) module.children.splice(idx, 1);
442-
});
443-
});
451+
}
452+
}
444453

445454
hotSetStatus("apply");
446455
// insert new code
447-
Object.keys(hotUpdate).forEach(function(moduleId) {
456+
for(var moduleId in hotUpdate) {
448457
var fn = hotUpdate[moduleId];
449458
if(fn) modules[moduleId] = fn;
450459
else delete modules[moduleId];
451-
});
460+
}
452461

453462
// call accept handlers
454463
var error = null;
455-
Object.keys(outdatedDependencies).forEach(function(moduleId) {
464+
for(var moduleId in outdatedDependencies) {
456465
var module = installedModules[moduleId];
457466
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
458467
var callbacks = [];
459-
moduleOutdatedDependencies.forEach(function(dependency) {
468+
for(var i = 0; i < moduleOutdatedDependencies.length; i++) {
469+
var dependency = moduleOutdatedDependencies[i];
460470
var cb = module.hot._acceptedDependencies[dependency];
461-
if(callbacks.indexOf(cb) >= 0) return;
471+
if(callbacks.indexOf(cb) >= 0) continue;
462472
callbacks.push(cb);
463-
});
464-
callbacks.forEach(function(cb) {
473+
}
474+
for(var i = 0; i < callbacks.length; i++) {
475+
var cb = callbacks[i];
465476
try {
466477
cb(outdatedDependencies);
467478
} catch(err) {
468479
if(!error)
469480
error = err;
470481
}
471-
});
472-
});
482+
}
483+
}
473484
if(error) {
474485
hotSetStatus("fail");
475486
return callback(error);
476487
}
477488

478489
// Load self accepted
479-
outdatedSelfAcceptedModules.forEach(function updateSelfAcceptedModules(moduleId) {
490+
for(var i = 0; i < outdatedSelfAcceptedModules.length; i++) {
491+
var moduleId = outdatedSelfAcceptedModules[i];
480492
hotCurrentParent = moduleId;
481493
$require$(moduleId);
482-
});
494+
}
483495

484496
hotCurrentHash = hotUpdateNewHash;
485497

0 commit comments

Comments
 (0)