Skip to content

Commit

Permalink
Expand explanatory comment, and fix custom overlay api
Browse files Browse the repository at this point in the history
  • Loading branch information
glenjamin committed Mar 10, 2016
1 parent cdabcc1 commit eac7366
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions client.js
Expand Up @@ -79,9 +79,13 @@ function connect(EventSource) {
}

var reporter;
// the reporter needs to be a singleton on the page.
if (typeof window !== 'undefined' && !window.__webpack_hot_middleware_reporter__) {
reporter = window.__webpack_hot_middleware_reporter__ = createReporter();
// the reporter needs to be a singleton on the page
// in case the client is being used by mutliple bundles
// we only want to report once.
// all the errors will go to all clients
var singletonKey = '__webpack_hot_middleware_reporter__';
if (typeof window !== 'undefined' && !window[singletonKey]) {
reporter = window[singletonKey] = createReporter();
}

function createReporter() {
Expand All @@ -102,9 +106,11 @@ function createReporter() {
}
if (overlay && type !== 'warnings') overlay.showProblems(type, obj[type]);
},

success: function() {
if (overlay) overlay.clear();
},
useCustomOverlay: function(customOverlay) {
overlay = customOverlay;
}
};
}
Expand All @@ -116,7 +122,12 @@ function processMessage(obj) {
if (obj.action == "building") {
if (options.log) console.log("[HMR] bundle rebuilding");
} else if (obj.action == "built") {
if (options.log) console.log("[HMR] bundle " + (obj.name ? obj.name + " " : "") + "rebuilt in " + obj.time + "ms");
if (options.log) {
console.log(
"[HMR] bundle " + (obj.name ? obj.name + " " : "") +
"rebuilt in " + obj.time + "ms"
);
}
if (obj.errors.length > 0) {
if (reporter) reporter.problems('errors', obj);
} else {
Expand All @@ -138,7 +149,7 @@ if (module) {
customHandler = handler;
},
useCustomOverlay: function useCustomOverlay(customOverlay) {
overlay = customOverlay;
if (reporter) reporter.useCustomOverlay(customOverlay);
}
};
}

0 comments on commit eac7366

Please sign in to comment.