This commit is contained in:
Seth Trowbridge 2023-06-15 23:08:24 -04:00
parent b042cf337a
commit 50aaaf136e
2 changed files with 26 additions and 19 deletions

View File

@ -1,3 +1,5 @@
import { type StateCapture } from "./react.tsx";
type FileHandler = (module:unknown)=>void type FileHandler = (module:unknown)=>void
const FileListeners = new Map() as Map<string, Array<FileHandler>>; const FileListeners = new Map() as Map<string, Array<FileHandler>>;
export const FileListen =(inPath:string, inHandler:()=>void)=> export const FileListen =(inPath:string, inHandler:()=>void)=>
@ -27,8 +29,8 @@ const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);
const HMR = { const HMR = {
reloads:0, reloads:0,
createdElements: new Map() as Map<string, ()=>void>, createdElements: new Map() as Map<string, ()=>void>,
states: new Map(), states: new Map() as Map<string, StateCapture>,
statesOld: new Map(), statesOld: new Map() as Map<string, StateCapture>,
wireframe: false, wireframe: false,
onChange(reactID:string, value:()=>void):void onChange(reactID:string, value:()=>void):void
{ {
@ -60,18 +62,4 @@ const HMR = {
} }
}; };
export {HMR}; export {HMR};
export const MapAt =(inMap, inIndex)=>
{
let index = 0;
for(const kvp of inMap)
{
if(index == inIndex)
{
return kvp;
}
index++;
}
return false;
};

View File

@ -1,5 +1,24 @@
import * as ReactParts from "react-original"; import * as ReactParts from "react-original";
import { HMR, MapAt } from "./hmr.tsx"; import { HMR } from "./hmr.tsx";
export type StateType = boolean|number|string|Record<string, string>
export type StateCapture = {state:StateType, set:ReactParts.StateUpdater<StateType>, reload:number};
const pluck =(m:Map<string, number>)=> m.keys()
const MapAt =(inMap:Map<string, StateCapture>, inIndex:number)=>
{
let index = 0;
for(const kvp of inMap)
{
if(index == inIndex)
{
return kvp;
}
index++;
}
return false;
};
const H = ReactParts.createElement; const H = ReactParts.createElement;
@ -29,7 +48,7 @@ const ProxyCreate =(...args)=>
return typeof args[0] != "string" ? H(ProxyElement, {__args:args, ...args[1]}) : H(...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 id = ReactParts.useId();
const trueArg = arg; const trueArg = arg;