From b0f87d20c5cfb70233badc416aeaebc7c32580a7 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Mon, 16 Oct 2023 10:27:22 -0400 Subject: [PATCH 1/3] signal hmr! --- cli.tsx | 2 ++ deno.jsonc | 2 +- hmr-listen.tsx | 13 +++++++++---- hmr-react.tsx | 5 +---- hmr-signal.tsx | 33 +++++++++++++++++++++++++++------ 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/cli.tsx b/cli.tsx index 931c240..d81d589 100644 --- a/cli.tsx +++ b/cli.tsx @@ -127,6 +127,8 @@ if(arg._.length) ...scanProd, ...Deno.args, RootHost+"run.tsx"]); + + break; } case "upgrade" : { diff --git a/deno.jsonc b/deno.jsonc index 8c5bac3..1837ba3 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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", diff --git a/hmr-listen.tsx b/hmr-listen.tsx index 9a444a8..87b326d 100644 --- a/hmr-listen.tsx +++ b/hmr-listen.tsx @@ -1,6 +1,5 @@ -type Processor = (filename:string)=>void; -const Processors:Set = new Set(); -export const Process =(p:Processor)=>Processors.add(p) +import { HMR } from "./hmr-react.tsx"; +import { recordEntrySwap, recordIndexReset } from "./hmr-signal.tsx"; const FileListeners = new Map() as Mapvoid>>; 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 // send the updated members to any listeners for that file + + recordIndexReset(); + 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)) + + recordEntrySwap(); + HMR.update(); + }); Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")}) const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000); \ No newline at end of file diff --git a/hmr-react.tsx b/hmr-react.tsx index 444bc11..13dae0d 100644 --- a/hmr-react.tsx +++ b/hmr-react.tsx @@ -27,7 +27,7 @@ When there is an HMR update: - statesNew is cleared. */ -const HMR = +export const HMR = { reloads:1, RegisteredComponents: new Map() as Mapvoid>, @@ -47,9 +47,6 @@ const HMR = this.statesNew = new Map(); } }; -Process(()=>HMR.update()) - - export type StateType = boolean|number|string|Record diff --git a/hmr-signal.tsx b/hmr-signal.tsx index 5febad0..7b9a9ca 100644 --- a/hmr-signal.tsx +++ b/hmr-signal.tsx @@ -1,14 +1,35 @@ import * as SignalsParts from "signals-original"; -import { Process } from "./hmr-listen.tsx"; +type Entry = [signal:SignalsParts.Signal, 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)=> { - console.log("---hmr---", arg); - return SignalsParts.signal(arg); -} + const lookupOld = recordEntry[recordIndex]; + 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 { proxySignal as signal }; From 7824b47634e11b37d31cf3c68d3df551954a9a71 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Mon, 16 Oct 2023 12:33:07 -0400 Subject: [PATCH 2/3] hmr signal hook! --- hmr-listen.tsx | 9 ++++--- hmr-react.tsx | 2 -- hmr-signal.tsx | 65 ++++++++++++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/hmr-listen.tsx b/hmr-listen.tsx index 87b326d..cd029b3 100644 --- a/hmr-listen.tsx +++ b/hmr-listen.tsx @@ -1,5 +1,5 @@ import { HMR } from "./hmr-react.tsx"; -import { recordEntrySwap, recordIndexReset } from "./hmr-signal.tsx"; +import { GroupSignal, GroupSignalHook } from "./hmr-signal.tsx"; const FileListeners = new Map() as Mapvoid>>; export const FileListen =(inPath:string, inHandler:()=>void)=> @@ -15,13 +15,16 @@ 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 - recordIndexReset(); + GroupSignal.reset(); const reImport = await import(document.location.origin+event.data+"?reload="+Math.random()); FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport)); - recordEntrySwap(); + GroupSignal.swap(); + + GroupSignalHook.reset(); HMR.update(); + GroupSignalHook.reset(); }); Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")}) diff --git a/hmr-react.tsx b/hmr-react.tsx index 13dae0d..9f1f6a9 100644 --- a/hmr-react.tsx +++ b/hmr-react.tsx @@ -1,6 +1,4 @@ import * as ReactParts from "react-original"; -import { Process } from "./hmr-listen.tsx"; - /* diff --git a/hmr-signal.tsx b/hmr-signal.tsx index 7b9a9ca..28703a9 100644 --- a/hmr-signal.tsx +++ b/hmr-signal.tsx @@ -1,37 +1,46 @@ import * as SignalsParts from "signals-original"; -type Entry = [signal:SignalsParts.Signal, initArg:unknown]; +type Entry = [signal:SignalsParts.Signal, initArg:T]; -let recordEntry:Entry[] = []; -let recordEntryNew:Entry[] = []; -let recordIndex = 0; -export const recordIndexReset =()=> recordIndex = 0; -export const recordEntrySwap =()=> +function ProxyGroup(inFunc:(initArg:T)=>SignalsParts.Signal) { - recordEntry = recordEntryNew; - recordEntryNew = [] as Entry[]; -}; -const proxySignal =(arg)=> -{ - const lookupOld = recordEntry[recordIndex]; - if(lookupOld && lookupOld[1] === arg) + let recordEntry:Entry[] = []; + let recordEntryNew:Entry[] = []; + let recordIndex = 0; + const reset =()=> recordIndex = 0; + const swap =()=> { - recordEntryNew[recordIndex] = lookupOld; - recordIndex++; - return lookupOld[0]; - } - else + recordEntry = recordEntryNew; + recordEntryNew = [] as Entry[]; + }; + const proxy =(arg:T)=> { - const sig = SignalsParts.signal(arg); - recordEntryNew[recordIndex] = [sig, arg]; - recordEntry[recordIndex] = [sig, arg]; - recordIndex++; - return sig; - } -}; + 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}; \ No newline at end of file +export { proxySignal as signal, proxySignalHook as useSignal }; +export default {...SignalsParts, signal:proxySignal, useSignal:proxySignalHook}; \ No newline at end of file From 4f90a33a935d59dd8c0987ae4e7e79518aba42be Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Mon, 16 Oct 2023 13:29:10 -0400 Subject: [PATCH 3/3] deploy exclusion --- cli.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cli.tsx b/cli.tsx index d81d589..0bc3741 100644 --- a/cli.tsx +++ b/cli.tsx @@ -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,11 @@ 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; }