let source; function check() { if (typeof module === 'undefined') return; 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://${window.location.hostname}:${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(); } }; }