diff --git a/_lib_/hmr.tsx b/_lib_/hmr.tsx index d293d84..274b968 100644 --- a/_lib_/hmr.tsx +++ b/_lib_/hmr.tsx @@ -1,3 +1,5 @@ +import { type StateCapture } from "./react.tsx"; + type FileHandler = (module:unknown)=>void const FileListeners = new Map() as Map>; export const FileListen =(inPath:string, inHandler:()=>void)=> @@ -27,8 +29,8 @@ const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000); const HMR = { reloads:0, createdElements: new Map() as Mapvoid>, - states: new Map(), - statesOld: new Map(), + states: new Map() as Map, + statesOld: new Map() as Map, wireframe: false, onChange(reactID:string, value:()=>void):void { @@ -60,18 +62,4 @@ const HMR = { } }; -export {HMR}; - -export const MapAt =(inMap, inIndex)=> -{ - let index = 0; - for(const kvp of inMap) - { - if(index == inIndex) - { - return kvp; - } - index++; - } - return false; -}; \ No newline at end of file +export {HMR}; \ No newline at end of file diff --git a/_lib_/react.tsx b/_lib_/react.tsx index 3b013cd..042307d 100644 --- a/_lib_/react.tsx +++ b/_lib_/react.tsx @@ -1,5 +1,24 @@ import * as ReactParts from "react-original"; -import { HMR, MapAt } from "./hmr.tsx"; +import { HMR } from "./hmr.tsx"; + +export type StateType = boolean|number|string|Record +export type StateCapture = {state:StateType, set:ReactParts.StateUpdater, reload:number}; + +const pluck =(m:Map)=> m.keys() + +const MapAt =(inMap:Map, inIndex:number)=> +{ + let index = 0; + for(const kvp of inMap) + { + if(index == inIndex) + { + return kvp; + } + index++; + } + return false; +}; const H = ReactParts.createElement; @@ -29,7 +48,7 @@ const ProxyCreate =(...args)=> return typeof args[0] != "string" ? H(ProxyElement, {__args:args, ...args[1]}) : H(...args); }; -const ProxyState =(arg)=> +const ProxyState =(arg:StateType)=> { const id = ReactParts.useId(); const trueArg = arg;