more progress
This commit is contained in:
parent
68b747c9ff
commit
7e6377d5ef
@ -2,10 +2,13 @@
|
|||||||
"compilerOptions": {"lib": [
|
"compilerOptions": {"lib": [
|
||||||
"deno.window", "DOM"
|
"deno.window", "DOM"
|
||||||
]},
|
]},
|
||||||
"importMap": "deno.map.json",
|
"imports": {
|
||||||
|
"react-original": "https://esm.sh/react@18.2.0"
|
||||||
|
},
|
||||||
"tasks":
|
"tasks":
|
||||||
{
|
{
|
||||||
"install": "deno install -f -A --unstable --no-lock -n eno server.tsx",
|
"install": "deno install -f -A --unstable --no-lock -n eno server.tsx",
|
||||||
"run": "deno run -A --unstable --no-lock server.tsx"
|
"run": "deno run -A --unstable --no-lock server.tsx",
|
||||||
|
"host": "deno run -A --unstable https://deno.land/std@0.181.0/http/file_server.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"imports": {
|
|
||||||
"react-original": "https://esm.sh/react@18.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
19
lib/hmr.tsx
19
lib/hmr.tsx
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
let reloads = 0;
|
let reloads = 0;
|
||||||
const listeners = new Map();
|
const listeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
|
||||||
new WebSocket("ws://"+document.location.host).addEventListener('message', (event) =>
|
new WebSocket("ws://"+document.location.host).addEventListener('message', (event) =>
|
||||||
{
|
{
|
||||||
let handlers = listeners.get(event.data)??[];
|
let handlers = listeners.get(event.data)??[];
|
||||||
@ -11,22 +11,27 @@ new WebSocket("ws://"+document.location.host).addEventListener('message', (event
|
|||||||
return import(event.data+"?reload="+reloads)
|
return import(event.data+"?reload="+reloads)
|
||||||
.then(updatedModule=>handler(updatedModule));
|
.then(updatedModule=>handler(updatedModule));
|
||||||
})
|
})
|
||||||
).then(HMR.update);
|
).then(()=>HMR.update());
|
||||||
});
|
});
|
||||||
|
|
||||||
export const HMR = {
|
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
||||||
|
{
|
||||||
|
const members = listeners.get(inPath)??[];
|
||||||
|
members.push(inHandler);
|
||||||
|
listeners.set(inPath, members);
|
||||||
|
};
|
||||||
|
|
||||||
|
const HMR = {
|
||||||
registered: new Map() as Map<string, ()=>void>,
|
registered: new Map() as Map<string, ()=>void>,
|
||||||
states: new Map(),
|
states: new Map(),
|
||||||
statesOld: new Map(),
|
statesOld: new Map(),
|
||||||
reloads: 0,
|
wireframe: true,
|
||||||
wireframe: false,
|
|
||||||
onChange(key:string, value:()=>void):void
|
onChange(key:string, value:()=>void):void
|
||||||
{
|
{
|
||||||
this.registered.set(key, value);
|
this.registered.set(key, value);
|
||||||
},
|
},
|
||||||
update()
|
update()
|
||||||
{
|
{
|
||||||
this.reloads++;
|
|
||||||
this.registered.forEach(handler=>handler());
|
this.registered.forEach(handler=>handler());
|
||||||
this.registered.clear();
|
this.registered.clear();
|
||||||
this.statesOld = this.states;
|
this.statesOld = this.states;
|
||||||
@ -50,6 +55,8 @@ export const HMR = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export {HMR};
|
||||||
|
|
||||||
export const MapAt =(inMap, inIndex)=>
|
export const MapAt =(inMap, inIndex)=>
|
||||||
{
|
{
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
import * as FS from "https://deno.land/std@0.144.0/fs/mod.ts";
|
|
||||||
|
|
||||||
console.log(Deno.args, import.meta.url);
|
|
||||||
/*
|
|
||||||
await Deno.mkdir("deep");
|
|
||||||
await Deno.create(`deep/file.txt`, "sup");
|
|
||||||
*/
|
|
17
server.tsx
17
server.tsx
@ -103,6 +103,7 @@ try
|
|||||||
{
|
{
|
||||||
ImportObject.imports["react-original"] = importReact;
|
ImportObject.imports["react-original"] = importReact;
|
||||||
ImportObject.imports["react"] = "/lib/react.tsx";
|
ImportObject.imports["react"] = "/lib/react.tsx";
|
||||||
|
ImportObject.imports["hmr"] = "/lib/hmr.tsx";
|
||||||
ImportString = JSON.stringify(ImportObject);
|
ImportString = JSON.stringify(ImportObject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -147,9 +148,13 @@ const Index = `
|
|||||||
ShadowDOM.append(ShadowCSS);
|
ShadowDOM.append(ShadowCSS);
|
||||||
ShadowDOM.append(ShadowDiv);
|
ShadowDOM.append(ShadowDiv);
|
||||||
|
|
||||||
import App from "./app.tsx";
|
|
||||||
App(ShadowDiv, Configure);
|
App(ShadowDiv, Configure);
|
||||||
TW.observe(TW.twind(Configure, TW.cssom(ShadowCSS)), ShadowDiv);
|
TW.observe(TW.twind(Configure, TW.cssom(ShadowCSS)), ShadowDiv);
|
||||||
|
|
||||||
|
import App from "./app.tsx";
|
||||||
|
import React from "react";
|
||||||
|
React.render(React.createElement(App), ShadowDiv);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -212,13 +217,17 @@ Deno.serve({ port: 3000 }, async(_req:Request) =>
|
|||||||
const members = [];
|
const members = [];
|
||||||
for( const key in imp ) { members.push(key); }
|
for( const key in imp ) { members.push(key); }
|
||||||
body =
|
body =
|
||||||
`import * as Import from "${url.pathname}?reload=0";
|
`
|
||||||
${ members.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join(" ") }
|
import {FileListen} from "hmr";
|
||||||
|
import * as Import from "${url.pathname}?reload=0";
|
||||||
|
${ members.map(m=>`let proxy_${m} = Import.${m};
|
||||||
|
export { proxy_${m} as ${m} };
|
||||||
|
`).join(" ") }
|
||||||
const reloadHandler = (updatedModule)=>
|
const reloadHandler = (updatedModule)=>
|
||||||
{
|
{
|
||||||
${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") }
|
${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") }
|
||||||
};
|
};
|
||||||
window.HMR("${url.pathname}", reloadHandler);`;
|
FileListen("${url.pathname}", reloadHandler);`;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user