dreaded-fixes #7
2
cli.tsx
2
cli.tsx
@ -127,6 +127,8 @@ if(arg._.length)
|
|||||||
...scanProd,
|
...scanProd,
|
||||||
...Deno.args,
|
...Deno.args,
|
||||||
RootHost+"run.tsx"]);
|
RootHost+"run.tsx"]);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case "upgrade" :
|
case "upgrade" :
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"debug": "deno run -A --no-lock http://localhost:4507/cli.tsx debug",
|
"debug": "deno run -A --no-lock http://localhost:4507/cli.tsx debug",
|
||||||
"serve": "deno run -A --no-lock http://localhost:4507/cli.tsx serve",
|
"serve": "deno run -A --no-lock http://localhost:4507/cli.tsx serve",
|
||||||
"cloud": "deno run -A --no-lock http://localhost:4507/cli.tsx cloud",
|
"cloud": "deno run -A --no-lock http://localhost:4507/cli.tsx cloud",
|
||||||
"install": "deno install -A -r -f http://localhost:4507/cli.tsx"
|
"install": "deno install -A -r -f -n able http://localhost:4507/cli.tsx"
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
type Processor = (filename:string)=>void;
|
import { HMR } from "./hmr-react.tsx";
|
||||||
const Processors:Set<Processor> = new Set();
|
import { recordEntrySwap, recordIndexReset } from "./hmr-signal.tsx";
|
||||||
export const Process =(p:Processor)=>Processors.add(p)
|
|
||||||
|
|
||||||
const FileListeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
|
const FileListeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
|
||||||
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
||||||
@ -15,9 +14,15 @@ Socket.addEventListener('message', async(event:{data:string})=>
|
|||||||
{
|
{
|
||||||
// When a file changes, dynamically re-import it to get the updated members
|
// When a file changes, dynamically re-import it to get the updated members
|
||||||
// send the updated members to any listeners for that file
|
// send the updated members to any listeners for that file
|
||||||
|
|
||||||
|
recordIndexReset();
|
||||||
|
|
||||||
const reImport = await import(document.location.origin+event.data+"?reload="+Math.random());
|
const reImport = await import(document.location.origin+event.data+"?reload="+Math.random());
|
||||||
FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport));
|
FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport));
|
||||||
Processors.forEach(p=>p(event.data))
|
|
||||||
|
recordEntrySwap();
|
||||||
|
HMR.update();
|
||||||
|
|
||||||
});
|
});
|
||||||
Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")})
|
Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")})
|
||||||
const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);
|
const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);
|
@ -27,7 +27,7 @@ When there is an HMR update:
|
|||||||
- statesNew is cleared.
|
- statesNew is cleared.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const HMR =
|
export const HMR =
|
||||||
{
|
{
|
||||||
reloads:1,
|
reloads:1,
|
||||||
RegisteredComponents: new Map() as Map<string, ()=>void>,
|
RegisteredComponents: new Map() as Map<string, ()=>void>,
|
||||||
@ -47,9 +47,6 @@ const HMR =
|
|||||||
this.statesNew = new Map();
|
this.statesNew = new Map();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Process(()=>HMR.update())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type StateType = boolean|number|string|Record<string, string>
|
export type StateType = boolean|number|string|Record<string, string>
|
||||||
|
@ -1,14 +1,35 @@
|
|||||||
import * as SignalsParts from "signals-original";
|
import * as SignalsParts from "signals-original";
|
||||||
import { Process } from "./hmr-listen.tsx";
|
|
||||||
|
|
||||||
|
type Entry = [signal:SignalsParts.Signal<unknown>, initArg:unknown];
|
||||||
|
|
||||||
const s1 = SignalsParts.signal(true);
|
let recordEntry:Entry[] = [];
|
||||||
|
let recordEntryNew:Entry[] = [];
|
||||||
|
let recordIndex = 0;
|
||||||
|
export const recordIndexReset =()=> recordIndex = 0;
|
||||||
|
export const recordEntrySwap =()=>
|
||||||
|
{
|
||||||
|
recordEntry = recordEntryNew;
|
||||||
|
recordEntryNew = [] as Entry[];
|
||||||
|
};
|
||||||
const proxySignal =(arg)=>
|
const proxySignal =(arg)=>
|
||||||
{
|
{
|
||||||
console.log("---hmr---", arg);
|
const lookupOld = recordEntry[recordIndex];
|
||||||
return SignalsParts.signal(arg);
|
if(lookupOld && lookupOld[1] === arg)
|
||||||
|
{
|
||||||
|
recordEntryNew[recordIndex] = lookupOld;
|
||||||
|
recordIndex++;
|
||||||
|
return lookupOld[0];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const sig = SignalsParts.signal(arg);
|
||||||
|
recordEntryNew[recordIndex] = [sig, arg];
|
||||||
|
recordEntry[recordIndex] = [sig, arg];
|
||||||
|
recordIndex++;
|
||||||
|
return sig;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export * from "signals-original";
|
export * from "signals-original";
|
||||||
export { proxySignal as signal };
|
export { proxySignal as signal };
|
||||||
|
Loading…
Reference in New Issue
Block a user