dreaded-fixes #7

Merged
SethTrowbridge merged 7 commits from dreaded-fixes into master 2023-10-16 13:30:24 -04:00
3 changed files with 43 additions and 33 deletions
Showing only changes of commit 7824b47634 - Show all commits

View File

@ -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 Map<string, Array<(module:unknown)=>void>>;
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")})

View File

@ -1,6 +1,4 @@
import * as ReactParts from "react-original";
import { Process } from "./hmr-listen.tsx";
/*

View File

@ -1,37 +1,46 @@
import * as SignalsParts from "signals-original";
type Entry = [signal:SignalsParts.Signal<unknown>, initArg:unknown];
type Entry<T> = [signal:SignalsParts.Signal<T>, initArg:T];
let recordEntry:Entry[] = [];
let recordEntryNew:Entry[] = [];
let recordIndex = 0;
export const recordIndexReset =()=> recordIndex = 0;
export const recordEntrySwap =()=>
function ProxyGroup<T>(inFunc:(initArg:T)=>SignalsParts.Signal<T>)
{
recordEntry = recordEntryNew;
recordEntryNew = [] as Entry[];
};
const proxySignal =(arg)=>
{
const lookupOld = recordEntry[recordIndex];
if(lookupOld && lookupOld[1] === arg)
let recordEntry:Entry<T>[] = [];
let recordEntryNew:Entry<T>[] = [];
let recordIndex = 0;
const reset =()=> recordIndex = 0;
const swap =()=>
{
recordEntryNew[recordIndex] = lookupOld;
recordIndex++;
return lookupOld[0];
}
else
recordEntry = recordEntryNew;
recordEntryNew = [] as Entry<T>[];
};
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};
export { proxySignal as signal, proxySignalHook as useSignal };
export default {...SignalsParts, signal:proxySignal, useSignal:proxySignalHook};