boot-function #1
@ -1,28 +1,29 @@
|
|||||||
|
type FileHandler = (module:unknown)=>void
|
||||||
let reloads = 0;
|
const FileListeners = new Map() as Map<string, Array<FileHandler>>;
|
||||||
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);
|
|
||||||
|
|
||||||
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
||||||
{
|
{
|
||||||
const members = listeners.get(inPath)??[];
|
const members = FileListeners.get(inPath)??[];
|
||||||
members.push(inHandler);
|
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 = {
|
const HMR = {
|
||||||
reloads:0,
|
reloads:0,
|
||||||
registered: new Map() as Map<string, ()=>void>,
|
registered: new Map() as Map<string, ()=>void>,
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": { "lib": ["deno.window", "dom"],
|
"compilerOptions": { "lib": ["deno.window", "dom"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "https://esm.sh/preact@10.15.1"
|
"jsxImportSource": "https://esm.sh/preact@10.15.1/compat"
|
||||||
},
|
},
|
||||||
"imports":
|
"imports":
|
||||||
{
|
{
|
||||||
"react":"https://esm.sh/preact@10.15.1/compat",
|
"react":"https://esm.sh/preact@10.15.1/compat",
|
||||||
"react-original":"https://esm.sh/preact@10.15.1/compat",
|
"react-original":"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,13 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
|
const CTX = React.createContext("lol");
|
||||||
|
|
||||||
export default ()=>
|
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>
|
||||||
}
|
}
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,6 +22,7 @@ Configure({
|
|||||||
},
|
},
|
||||||
Remap: (inImports)=>
|
Remap: (inImports)=>
|
||||||
{
|
{
|
||||||
|
console.log("running remapper");
|
||||||
Object.entries(inImports).forEach(([key, value])=>
|
Object.entries(inImports).forEach(([key, value])=>
|
||||||
{
|
{
|
||||||
if(value.startsWith("./"))
|
if(value.startsWith("./"))
|
||||||
|
@ -143,7 +143,11 @@ export const Extension =(inPath:string)=>
|
|||||||
return posDot > posSlash ? inPath.substring(posDot+1).toLowerCase() : false;
|
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 ImportMapReload();
|
||||||
await SWCW.default();
|
await SWCW.default();
|
||||||
|
Loading…
Reference in New Issue
Block a user