From b042cf337a30db45f8e468cb6501acad6a8763d2 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Thu, 15 Jun 2023 17:50:55 -0400 Subject: [PATCH] more tweaks --- _lib_/hmr.tsx | 12 ++++++------ example/app.tsx | 2 +- example/deno.json | 5 +++++ local.tsx | 22 +++++++++++----------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/_lib_/hmr.tsx b/_lib_/hmr.tsx index d76d7e6..d293d84 100644 --- a/_lib_/hmr.tsx +++ b/_lib_/hmr.tsx @@ -18,7 +18,7 @@ Socket.addEventListener('message', (event:{data:string})=> return import(event.data+"?reload="+SocketReloads) .then(updatedModule=>handler(updatedModule)); }) - ).then(HMR.update); + ).then(()=>HMR.update()); }); let SocketReloads = 0; // heartbeat @@ -26,19 +26,19 @@ const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000); const HMR = { reloads:0, - registered: new Map() as Mapvoid>, + createdElements: new Map() as Mapvoid>, states: new Map(), statesOld: new Map(), wireframe: false, - onChange(key:string, value:()=>void):void + onChange(reactID:string, value:()=>void):void { - this.registered.set(key, value); + this.createdElements.set(reactID, value); }, update() { this.reloads++; - this.registered.forEach(handler=>handler()); - this.registered.clear(); + this.createdElements.forEach(handler=>handler()); + this.createdElements.clear(); this.statesOld = this.states; this.states = new Map(); this.echoState(); diff --git a/example/app.tsx b/example/app.tsx index 3814f18..29f3e8b 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -5,7 +5,7 @@ const CTX = React.createContext("lol"); export default ()=> { return -

hey!?

+

hey!

{(value)=>} diff --git a/example/deno.json b/example/deno.json index 8256efb..9f0718b 100644 --- a/example/deno.json +++ b/example/deno.json @@ -4,5 +4,10 @@ { "react":"https://esm.sh/preact@10.15.1/compat", "app": "./app.tsx" + }, + "tasks": + { + "local": "deno run -A --no-lock ../local.tsx", + "serve": "deno run -A --no-lock ../serve.tsx" } } \ No newline at end of file diff --git a/local.tsx b/local.tsx index d30567d..aee018c 100644 --- a/local.tsx +++ b/local.tsx @@ -43,17 +43,17 @@ Configure({ const imp = await import(Directory+inURL.pathname); const members = []; for( const key in imp ) { members.push(key); } - return new Response(`import {FileListen} from "/_lib_/hmr.tsx"; - import * as Import from "${inURL.pathname}?reload=0"; - ${ members.map(m=>`let proxy_${m} = Import.${m}; - export { proxy_${m} as ${m} }; - `).join(" ") } - const reloadHandler = (updatedModule)=> - { - ${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } - }; - FileListen("${inURL.pathname}", reloadHandler);`, {headers:{"content-type":"application/javascript"}} - ); + + const code =` +import {FileListen} from "/_lib_/hmr.tsx"; +import * as Import from "${inURL.pathname}?reload=0"; +${ members.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } +FileListen("${inURL.pathname}", (updatedModule)=> +{ + ${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } +});` + + return new Response(code, {headers:{"content-type":"application/javascript"}}); }