boot-function #1
@ -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 Map<string, ()=>void>,
|
||||
createdElements: new Map() as Map<string, ()=>void>,
|
||||
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();
|
||||
|
@ -5,7 +5,7 @@ const CTX = React.createContext("lol");
|
||||
export default ()=>
|
||||
{
|
||||
return <CTX.Provider value="intradestink">
|
||||
<div><h1>hey!?</h1></div>
|
||||
<div><h1>hey!</h1></div>
|
||||
<CTX.Consumer>
|
||||
{(value)=><button>{value}</button>}
|
||||
</CTX.Consumer>
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
22
local.tsx
22
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"}});
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user