hmr fixes
allow page refresh, add keep-alive ping
This commit is contained in:
parent
d3f08a67a0
commit
8a1b7e7dbd
@ -3,8 +3,6 @@
|
||||
"imports":
|
||||
{
|
||||
"react": "https://esm.sh/stable/preact@10.13.2/compat",
|
||||
"preact": "https://esm.sh/stable/preact@10.13.2/",
|
||||
"@deep/": "./deep/",
|
||||
"@eno/app": "./app.tsx",
|
||||
"@eno/iso": "http://localhost:4507/lib/iso.tsx"
|
||||
},
|
||||
|
@ -1,7 +1,8 @@
|
||||
|
||||
let reloads = 0;
|
||||
const listeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
|
||||
new WebSocket("ws://"+document.location.host).addEventListener('message', (event) =>
|
||||
const socket:WebSocket = new WebSocket("ws://"+document.location.host);
|
||||
socket.addEventListener('message', (event) =>
|
||||
{
|
||||
let handlers = listeners.get(event.data)??[];
|
||||
reloads++;
|
||||
@ -13,6 +14,7 @@ new WebSocket("ws://"+document.location.host).addEventListener('message', (event
|
||||
})
|
||||
).then(()=>HMR.update());
|
||||
});
|
||||
const socketTimer = setInterval(()=>{socket.send("ping")}, 1000);
|
||||
|
||||
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
||||
{
|
||||
|
11
server.tsx
11
server.tsx
@ -89,6 +89,7 @@ function Transpiler(inDevMode:boolean)
|
||||
:
|
||||
()=>false;
|
||||
|
||||
let reloads = 0;
|
||||
const watcher =async()=>
|
||||
{
|
||||
const FilesChanged:Map<string, string> = new Map();
|
||||
@ -99,6 +100,13 @@ function Transpiler(inDevMode:boolean)
|
||||
const key = path.substring(Deno.cwd().length).replaceAll("\\", "/");
|
||||
if(action != "remove")
|
||||
{
|
||||
if(Imports?.imports)
|
||||
{
|
||||
reloads++;
|
||||
const importApp = Imports.imports["@eno/app"];
|
||||
const imp = await import(Path.Active+importApp+"?reloads="+reloads);
|
||||
App = imp.default;
|
||||
}
|
||||
await TranspileURL(Path.Active+key, key, false);
|
||||
SocketsBroadcast(key);
|
||||
}
|
||||
@ -294,7 +302,8 @@ console.log(`Dev Mode: ${DevMode}`);
|
||||
console.log(`Args seen: `, Flags);
|
||||
|
||||
const {Transpileable, TranspileURL, SocketsHandler} = Transpiler(DevMode);
|
||||
const {Imports, App, TwindInst, Error} = await Configure(DevMode, Path.LibDir);
|
||||
let {Imports, App, TwindInst, Error} = await Configure(DevMode, Path.LibDir);
|
||||
|
||||
if(Error)
|
||||
{
|
||||
console.log(Error);
|
||||
|
Loading…
Reference in New Issue
Block a user