You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
1.9 KiB
2 lines
1.9 KiB
2 years ago
|
function d(i){let e;return i?(e=i.toIterable)?e.call(i):i:[]}var f=class{constructor(){this.start(),this.debug=!1}log(...e){return console.log(...e)}refresh(e){this.manifest=e;let t={css:[],js:[]},n=Object.values(e).map(function(r){return r.url}).filter(function(r){return r}),s=/\.[A-Z\d]{8}\./;for(let r of d(globalThis.document.styleSheets)){let o=r.ownerNode.getAttribute("href")||"",u=n.find(function(l){return l&&l.replace(s,"")==o.replace(s,"")});u&&o!=u&&(r.ownerNode.href=u)}let a=Object.keys(globalThis.IMBA_LOADED||{});for(let r=0,o=d(a),u=o.length;r<u;r++){let l=o[r],c=n.find(function(h){return h&&h.replace(s,"")==l.replace(s,"")});c&&l!=c&&n.indexOf(l)==-1&&t.js.push([l,c])}return t.js.length&&globalThis.document.location.reload(),this}start(){var e=this;if(!this.socket)return this.socket=new EventSource("/__hmr__"),e.socket.onmessage=function(t){return e.log("sse.onmessage",t)},e.socket.addEventListener("paused",function(t){return e.log("server paused"),!0}),e.socket.addEventListener("resumed",function(t){return e.log("server resumed"),!0}),e.socket.addEventListener("reloaded",function(t){return e.log("server reloaded"),setTimeout(function(){return e.socket.close(),e.socket=null,e.start()},200),!0}),e.socket.addEventListener("rebuild",function(t){let n=JSON.parse(t.data);return e.refresh(n)}),e.socket.addEventListener("init",function(t){let n=JSON.parse(t.data);return e.refresh(n)}),e.socket.addEventListener("state",function(t){let n=JSON.parse(t.data);return e.log("server state",n)}),e.socket.addEventListener("errors",function(t){let n=JSON.parse(t.data);for(let s=0,a=d(n),r=a.length;s<r;s++){let o=a[s];console.error("error in "+o.location.file+": "+o.location.lineText+" ("+o.text+")")}}),e.socket.addEventListener("reload",function(t){return e.log("asked to reload by server"),globalThis.document.location.reload()}),e.socket.onerror=function(t){return e.log("hmr disconnected",t)}}};globalThis.imba_devtools=new f;
|