This commit is contained in:
Seth Trowbridge 2023-06-15 17:13:51 -04:00
parent 0e6a3d3efb
commit fc674f2efb
6 changed files with 42 additions and 34 deletions

View File

@ -1,28 +1,29 @@
let reloads = 0;
const listeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
const socket:WebSocket = new WebSocket("ws://"+document.location.host);
socket.addEventListener('message', (event) =>
{
let handlers = listeners.get(event.data)??[];
reloads++;
Promise.all(
handlers.map(handler=>
{
return import(event.data+"?reload="+reloads)
.then(updatedModule=>handler(updatedModule));
})
).then(()=>HMR.update());
});
const socketTimer = setInterval(()=>{socket.send("ping")}, 1000);
type FileHandler = (module:unknown)=>void
const FileListeners = new Map() as Map<string, Array<FileHandler>>;
export const FileListen =(inPath:string, inHandler:()=>void)=>
{
const members = listeners.get(inPath)??[];
const members = FileListeners.get(inPath)??[];
members.push(inHandler);
listeners.set(inPath, members);
FileListeners.set(inPath, members);
};
const Socket:WebSocket = new WebSocket("ws://"+document.location.host);
Socket.addEventListener('message', (event:{data:string})=>
{
const handlers = FileListeners.get(event.data)??[];
SocketReloads++;
Promise.all(
handlers.map((handler)=>
{
return import(event.data+"?reload="+SocketReloads)
.then(updatedModule=>handler(updatedModule));
})
).then(HMR.update);
});
let SocketReloads = 0;
// heartbeat
const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);
const HMR = {
reloads:0,
registered: new Map() as Map<string, ()=>void>,

View File

@ -1,12 +1,17 @@
{
"compilerOptions": { "lib": ["deno.window", "dom"],
"jsx": "react-jsx",
"jsxImportSource": "https://esm.sh/preact@10.15.1"
"jsxImportSource": "https://esm.sh/preact@10.15.1/compat"
},
"imports":
{
"react":"https://esm.sh/preact@10.15.1/compat",
"react-original":"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"
}
}

View File

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

View File

@ -1,11 +0,0 @@
{
"version": "2",
"remote": {
"https://esm.sh/preact@10.13.2/compat/jsx-runtime": "cd2ac8b136b917d804161f394f0838e5b1643cd9a1f4ba7edc52e50caaa419d2",
"https://esm.sh/stable/preact@10.13.2/deno/compat.js": "3151a948abd84aa75dfc9e57733da7e1a45fff7a25de58c7b6025b923874b508",
"https://esm.sh/stable/preact@10.13.2/deno/compat/jsx-runtime.js": "e042cc9c6a59023f70840c4e6f9854fce0486241583e0e471c67d2b6cecf849f",
"https://esm.sh/stable/preact@10.13.2/deno/hooks.js": "c7a8e703bcbc6a05949f329b618c33d5d1ea5fee113ddcea44ff0f527af8556f",
"https://esm.sh/stable/preact@10.13.2/deno/jsx-runtime.js": "dd40c5bdfe7b277bf51009fb950c550dfb554b6d56a1b3a4cb9bc12bde84bcd1",
"https://esm.sh/stable/preact@10.13.2/deno/preact.mjs": "365fab897381f4f403f859c5d12939084560545567108cc90dae901bbe892578"
}
}

View File

@ -22,6 +22,7 @@ Configure({
},
Remap: (inImports)=>
{
console.log("running remapper");
Object.entries(inImports).forEach(([key, value])=>
{
if(value.startsWith("./"))

View File

@ -143,7 +143,11 @@ export const Extension =(inPath:string)=>
return posDot > posSlash ? inPath.substring(posDot+1).toLowerCase() : false;
};
export const Configure =(config:ConfigurationArgs)=> Configuration = {...Configuration, ...config};
export const Configure =(config:ConfigurationArgs)=>
{
Configuration = {...Configuration, ...config};
ImportMapReload();
}
await ImportMapReload();
await SWCW.default();