various stability improvements

This commit is contained in:
Rich Harris
2018-03-03 21:48:50 -05:00
parent ff3b43443e
commit 99853c5181
7 changed files with 102 additions and 111 deletions

38
sapper-dev-client.js Normal file
View File

@@ -0,0 +1,38 @@
let source;
function check() {
if (module.hot.status() === 'idle') {
module.hot.check(true).then(modules => {
console.log(`[SAPPER] applied HMR update`);
});
}
}
export function connect(port) {
if (source || !window.EventSource) return;
source = new EventSource(`http://localhost:${port}/__sapper__`);
window.source = source;
source.onopen = function(event) {
console.log(`[SAPPER] dev client connected`);
};
source.onerror = function(error) {
console.error(error);
};
source.onmessage = function(event) {
const data = JSON.parse(event.data);
if (!data) return; // just a heartbeat
if (data.action === 'reload') {
window.location.reload();
}
if (data.status === 'completed') {
check();
}
};
}