more tweaks

This commit is contained in:
Seth Trowbridge 2023-06-15 17:50:55 -04:00
parent fc674f2efb
commit b042cf337a
4 changed files with 23 additions and 18 deletions

View File

@ -18,7 +18,7 @@ Socket.addEventListener('message', (event:{data:string})=>
return import(event.data+"?reload="+SocketReloads) return import(event.data+"?reload="+SocketReloads)
.then(updatedModule=>handler(updatedModule)); .then(updatedModule=>handler(updatedModule));
}) })
).then(HMR.update); ).then(()=>HMR.update());
}); });
let SocketReloads = 0; let SocketReloads = 0;
// heartbeat // heartbeat
@ -26,19 +26,19 @@ const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);
const HMR = { const HMR = {
reloads:0, reloads:0,
registered: new Map() as Map<string, ()=>void>, createdElements: new Map() as Map<string, ()=>void>,
states: new Map(), states: new Map(),
statesOld: new Map(), statesOld: new Map(),
wireframe: false, 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() update()
{ {
this.reloads++; this.reloads++;
this.registered.forEach(handler=>handler()); this.createdElements.forEach(handler=>handler());
this.registered.clear(); this.createdElements.clear();
this.statesOld = this.states; this.statesOld = this.states;
this.states = new Map(); this.states = new Map();
this.echoState(); this.echoState();

View File

@ -5,7 +5,7 @@ const CTX = React.createContext("lol");
export default ()=> export default ()=>
{ {
return <CTX.Provider value="intradestink"> return <CTX.Provider value="intradestink">
<div><h1>hey!?</h1></div> <div><h1>hey!</h1></div>
<CTX.Consumer> <CTX.Consumer>
{(value)=><button>{value}</button>} {(value)=><button>{value}</button>}
</CTX.Consumer> </CTX.Consumer>

View File

@ -4,5 +4,10 @@
{ {
"react":"https://esm.sh/preact@10.15.1/compat", "react":"https://esm.sh/preact@10.15.1/compat",
"app": "./app.tsx" "app": "./app.tsx"
},
"tasks":
{
"local": "deno run -A --no-lock ../local.tsx",
"serve": "deno run -A --no-lock ../serve.tsx"
} }
} }

View File

@ -43,17 +43,17 @@ Configure({
const imp = await import(Directory+inURL.pathname); const imp = await import(Directory+inURL.pathname);
const members = []; const members = [];
for( const key in imp ) { members.push(key); } 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"; const code =`
${ members.map(m=>`let proxy_${m} = Import.${m}; import {FileListen} from "/_lib_/hmr.tsx";
export { proxy_${m} as ${m} }; import * as Import from "${inURL.pathname}?reload=0";
`).join(" ") } ${ members.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") }
const reloadHandler = (updatedModule)=> FileListen("${inURL.pathname}", (updatedModule)=>
{ {
${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } ${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") }
}; });`
FileListen("${inURL.pathname}", reloadHandler);`, {headers:{"content-type":"application/javascript"}}
); return new Response(code, {headers:{"content-type":"application/javascript"}});
} }