diff --git a/_lib_/hmr.tsx b/_lib_/hmr.tsx index 198981e..d76d7e6 100644 --- a/_lib_/hmr.tsx +++ b/_lib_/hmr.tsx @@ -1,28 +1,29 @@ - -let reloads = 0; -const listeners = new Map() as Mapvoid>>; -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>; 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 Mapvoid>, diff --git a/deno.json b/deno.json index 1f5fffd..a542f8e 100644 --- a/deno.json +++ b/deno.json @@ -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" } } \ No newline at end of file diff --git a/example/app.tsx b/example/app.tsx index 03c2ce0..3814f18 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -1,5 +1,13 @@ import React from "react"; + +const CTX = React.createContext("lol"); + export default ()=> { - return

hey!

+ return +

hey!?

+ + {(value)=>} + +
} \ No newline at end of file diff --git a/example/deno.lock b/example/deno.lock deleted file mode 100644 index b84dd19..0000000 --- a/example/deno.lock +++ /dev/null @@ -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" - } -} diff --git a/local.tsx b/local.tsx index ced1167..d30567d 100644 --- a/local.tsx +++ b/local.tsx @@ -22,6 +22,7 @@ Configure({ }, Remap: (inImports)=> { + console.log("running remapper"); Object.entries(inImports).forEach(([key, value])=> { if(value.startsWith("./")) diff --git a/serve.tsx b/serve.tsx index b50d80b..e224a03 100644 --- a/serve.tsx +++ b/serve.tsx @@ -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();