hmr fixes #25

Merged
SethTrowbridge merged 2 commits from redo-boot into master 2023-05-06 14:28:42 -04:00
3 changed files with 13 additions and 4 deletions
Showing only changes of commit 8a1b7e7dbd - Show all commits

View File

@ -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"
},

View File

@ -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)=>
{

View File

@ -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);