From 8a1b7e7dbd8c13cb79daab2b5dd1e2065db7e0d2 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 6 May 2023 09:51:55 -0400 Subject: [PATCH 1/2] hmr fixes allow page refresh, add keep-alive ping --- example/deno.jsonc | 2 -- lib/hmr.tsx | 4 +++- server.tsx | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/example/deno.jsonc b/example/deno.jsonc index 2c2f6e0..e191d55 100644 --- a/example/deno.jsonc +++ b/example/deno.jsonc @@ -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" }, diff --git a/lib/hmr.tsx b/lib/hmr.tsx index 59e1d1d..198981e 100644 --- a/lib/hmr.tsx +++ b/lib/hmr.tsx @@ -1,7 +1,8 @@ let reloads = 0; const listeners = new Map() as Mapvoid>>; -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)=> { diff --git a/server.tsx b/server.tsx index f912b27..ca01277 100644 --- a/server.tsx +++ b/server.tsx @@ -89,6 +89,7 @@ function Transpiler(inDevMode:boolean) : ()=>false; + let reloads = 0; const watcher =async()=> { const FilesChanged:Map = 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); -- 2.34.1 From de4f7608ba00f58a594903b5813d7002ef954294 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 6 May 2023 14:27:20 -0400 Subject: [PATCH 2/2] get rid of junk --- .vscode/launch.json | 24 ------------------------ deno.lock | 16 ---------------- fetch.test.tsx | 35 ----------------------------------- 3 files changed, 75 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 deno.lock delete mode 100644 fetch.test.tsx diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index a0c25b9..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "request": "launch", - "name": "Launch Program", - "type": "node", - "program": "${workspaceFolder}/server.tsx", - "cwd": "${workspaceFolder}", - "runtimeExecutable": "C:\\Users\\Seth\\.deno\\bin\\deno.EXE", - "runtimeArgs": [ - "run", - "--no-lock", - "--unstable", - "--inspect-wait", - "--allow-all" - ], - "attachSimplePort": 9229 - } - ] -} \ No newline at end of file diff --git a/deno.lock b/deno.lock deleted file mode 100644 index b8e174d..0000000 --- a/deno.lock +++ /dev/null @@ -1,16 +0,0 @@ -{ - "version": "2", - "remote": { - "http://localhost:4507/lib/iso.tsx": "edf1cf4c539900040c75824eac8472e0ec43098b13af4049bd79ddbd76a5346d", - "https://esm.sh/preact@10.13.2/compat": "1cf68e0c8c6c84b60d42f30665403b67229c16ff5206824709b19df60ba9cdc3", - "https://esm.sh/stable/preact@10.13.2/deno/compat.js": "3151a948abd84aa75dfc9e57733da7e1a45fff7a25de58c7b6025b923874b508", - "https://esm.sh/stable/preact@10.13.2/deno/hooks.js": "c7a8e703bcbc6a05949f329b618c33d5d1ea5fee113ddcea44ff0f527af8556f", - "https://esm.sh/stable/preact@10.13.2/deno/preact.mjs": "365fab897381f4f403f859c5d12939084560545567108cc90dae901bbe892578", - "https://esm.sh/v116/preact@10.13.2/compat/src/index.d.ts": "d02f015638a40e32649151e011cfda7b520d66f7fbd3c12a28fa03de2a5e1421", - "https://esm.sh/v116/preact@10.13.2/compat/src/suspense-list.d.ts": "b8e274324392157ce476ef3a48ae215c9f7003b08525d140645f19eab20d1948", - "https://esm.sh/v116/preact@10.13.2/compat/src/suspense.d.ts": "81f5266e0977a94347505d11b8103024211f2b4f3b2eb2aa276a10d8fd169e65", - "https://esm.sh/v116/preact@10.13.2/hooks/src/index.d.ts": "5c29febb624fc25d71cb0e125848c9b711e233337a08f7eacfade38fd4c14cc3", - "https://esm.sh/v116/preact@10.13.2/src/index.d.ts": "65398710de6aa0a07412da79784e05e6e96763f51c7c91b77344d2d0af06385c", - "https://esm.sh/v116/preact@10.13.2/src/jsx.d.ts": "9ac9b82c199fa7b04748807d750eba1a106c0be52041b8617416f88d6fc0a257" - } -} diff --git a/fetch.test.tsx b/fetch.test.tsx deleted file mode 100644 index 1a16c21..0000000 --- a/fetch.test.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import {Fetch} from "./lib/iso.tsx"; - - -const delay =async(inHandler:()=>void, inDelay:number):Promise=> -{ - return new Promise((accept)=>{ - setTimeout(()=>{ - accept(inHandler()); - }, inDelay); - }); -}; - -const queue = [1, 2, 3]; -while(queue.length) -{ - await(delay(()=>{console.log(queue.pop())}, 1000)) -} - -console.log("all done!"); - -/* -let r1, r2, r3; - -delay(()=>{r1 = Fetch.Request(`https://catfact.ninja/fact`, undefined, 0.2); console.log(r1); }, 10); -delay(()=>{r2 = Fetch.Request(`https://catfact.ninja/fact`, undefined, 0.2); console.log(r2); }, 20); -delay(()=>{r3 = Fetch.Request(`https://catfact.ninja/fact`, undefined, 0.2); console.log(r3); }, 2000); - - -await delay(()=>{}, 3000); - -console.log(r1); -console.log(r2); -console.log(r3); - -*/ \ No newline at end of file -- 2.34.1