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 { 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>>; const FileListeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
export const FileListen =(inPath:string, inHandler:()=>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 // When a file changes, dynamically re-import it to get the updated members
// send the updated members to any listeners for that file // 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()); const reImport = await import(document.location.origin+event.data+"?reload="+Math.random());
FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport)); FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport));
recordEntrySwap(); GroupSignal.swap();
GroupSignalHook.reset();
HMR.update(); HMR.update();
GroupSignalHook.reset();
}); });
Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")}) Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")})

View File

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

View File

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