Skip to content

Commit

Permalink
fallback when Object.defineProperty is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 22, 2016
1 parent d4573e5 commit 59c0c4a
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions lib/HotModuleReplacement.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,57 @@ module.exports = function() {
};
for(var name in $require$) {
if(Object.prototype.hasOwnProperty.call($require$, name)) {
Object.defineProperty(fn, name, (function(name) {
return {
configurable: true,
enumerable: true,
get: function() {
return $require$[name];
},
set: function(value) {
$require$[name] = value;
}
};
}(name)));
if(Object.defineProperty) {
Object.defineProperty(fn, name, (function(name) {
return {
configurable: true,
enumerable: true,
get: function() {
return $require$[name];
},
set: function(value) {
$require$[name] = value;
}
};
}(name)));
} else {
fn[name] = $require$[name];
}
}
}
Object.defineProperty(fn, "e", {
enumerable: true,
value: function(chunkId, callback) {
if(hotStatus === "ready")
hotSetStatus("prepare");
hotChunksLoading++;
$require$.e(chunkId, function() {
try {
callback.call(null, fn);
} finally {
finishChunkLoading();
}

function finishChunkLoading() {
hotChunksLoading--;
if(hotStatus === "prepare") {
if(!hotWaitingFilesMap[chunkId]) {
hotEnsureUpdateChunk(chunkId);
}
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
hotUpdateDownloaded();
}
function ensure(chunkId, callback) {
if(hotStatus === "ready")
hotSetStatus("prepare");
hotChunksLoading++;
$require$.e(chunkId, function() {
try {
callback.call(null, fn);
} finally {
finishChunkLoading();
}

function finishChunkLoading() {
hotChunksLoading--;
if(hotStatus === "prepare") {
if(!hotWaitingFilesMap[chunkId]) {
hotEnsureUpdateChunk(chunkId);
}
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
hotUpdateDownloaded();
}
}
});
}
});
}
});
}
if(Object.defineProperty) {
Object.defineProperty(fn, "e", {
enumerable: true,
value: ensure
});
} else {
fn.e = ensure;
}
return fn;
}

Expand Down

0 comments on commit 59c0c4a

Please sign in to comment.