Merge branch 'dreaded-fixes' of https://gitea.hptrow.me/SethTrowbridge/able-baker into dreaded-fixes

This commit is contained in:
Seth Trowbridge 2023-10-16 21:20:47 -04:00
commit fbe3959c07
5 changed files with 62 additions and 26 deletions

15
cli.tsx
View File

@ -99,8 +99,8 @@ if(arg._.length)
}
case "cloud" :
{
let useToken = await collect("DENO_DEPLOY_TOKEN", arg, env);
let useProject = await collect("DENO_DEPLOY_PROJECT", arg, env);
const useToken = await collect("DENO_DEPLOY_TOKEN", arg, env);
const useProject = await collect("DENO_DEPLOY_PROJECT", arg, env);
let scanProd:string[]|string|null = prompt(`Do you want to deploy to *production*?`);
if(scanProd)
@ -113,7 +113,7 @@ if(arg._.length)
scanProd = [];
}
await SubProcess([
const command = [
"run",
"-A",
"--no-lock",
@ -123,10 +123,13 @@ if(arg._.length)
`--project=${useProject}`,
`--token=${useToken}`,
`--import-map=${imports.path}`,
`--exclude=.*,.*/,`,
...scanProd,
...Deno.args,
RootHost+"run.tsx"]);
RootHost+"run.tsx"];
await SubProcess(command);
break;
}
case "upgrade" :
{

View File

@ -15,7 +15,7 @@
"debug": "deno run -A --no-lock http://localhost:4507/cli.tsx debug",
"serve": "deno run -A --no-lock http://localhost:4507/cli.tsx serve",
"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": {
"jsx": "react-jsx",

View File

@ -1,6 +1,5 @@
type Processor = (filename:string)=>void;
const Processors:Set<Processor> = new Set();
export const Process =(p:Processor)=>Processors.add(p)
import { HMR } from "./hmr-react.tsx";
import { GroupSignal, GroupSignalHook } from "./hmr-signal.tsx";
const FileListeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
export const FileListen =(inPath:string, inHandler:()=>void)=>
@ -15,9 +14,18 @@ Socket.addEventListener('message', async(event:{data:string})=>
{
// When a file changes, dynamically re-import it to get the updated members
// send the updated members to any listeners for that file
GroupSignal.reset();
const reImport = await import(document.location.origin+event.data+"?reload="+Math.random());
FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport));
Processors.forEach(p=>p(event.data))
GroupSignal.swap();
GroupSignalHook.reset();
HMR.update();
GroupSignalHook.reset();
});
Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")})
const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);

View File

@ -1,6 +1,4 @@
import * as ReactParts from "react-original";
import { Process } from "./hmr-listen.tsx";
/*
@ -27,7 +25,7 @@ When there is an HMR update:
- statesNew is cleared.
*/
const HMR =
export const HMR =
{
reloads:1,
RegisteredComponents: new Map() as Map<string, ()=>void>,
@ -47,9 +45,6 @@ const HMR =
this.statesNew = new Map();
}
};
Process(()=>HMR.update())
export type StateType = boolean|number|string|Record<string, string>

View File

@ -1,16 +1,46 @@
import * as SignalsParts from "signals-original";
import { Process } from "./hmr-listen.tsx";
type Entry<T> = [signal:SignalsParts.Signal<T>, initArg:T];
const s1 = SignalsParts.signal(true);
const proxySignal =(arg)=>
function ProxyGroup<T>(inFunc:(initArg:T)=>SignalsParts.Signal<T>)
{
console.log("---hmr---", arg);
return SignalsParts.signal(arg);
let recordEntry:Entry<T>[] = [];
let recordEntryNew:Entry<T>[] = [];
let recordIndex = 0;
const reset =()=> recordIndex = 0;
const swap =()=>
{
recordEntry = recordEntryNew;
recordEntryNew = [] as Entry<T>[];
};
const proxy =(arg:T)=>
{
const lookupOld = recordEntry[recordIndex];
if(lookupOld && lookupOld[1] === arg)
{
recordEntryNew[recordIndex] = lookupOld;
recordIndex++;
return lookupOld[0];
}
else
{
const sig = inFunc(arg);
recordEntryNew[recordIndex] = [sig, arg];
recordEntry[recordIndex] = [sig, arg];
recordIndex++;
return sig;
}
};
return {reset, swap, proxy};
}
export const GroupSignal = ProxyGroup(SignalsParts.signal);
export const GroupSignalHook = ProxyGroup(SignalsParts.useSignal);
const proxySignal = GroupSignal.proxy;
const proxySignalHook = GroupSignalHook.proxy;
export * from "signals-original";
export { proxySignal as signal };
// ? export {ProxyCreate as createElement, ProxyState as useState, ProxyReducer as useReducer };
// ? export default {...ReactParts, createElement:ProxyCreate, useState:ProxyState, useReducer:ProxyReducer};
export { proxySignal as signal, proxySignalHook as useSignal };
export default {...SignalsParts, signal:proxySignal, useSignal:proxySignalHook};