import * as SignalsParts from "signals-original"; import DeepEqual from "https://esm.sh/deep-eql@4.1.3"; type Entry = [signal:SignalsParts.Signal, initArg:T]; function ProxyGroup(inFunc:(initArg:T)=>SignalsParts.Signal) { let recordEntry:Entry[] = []; let recordEntryNew:Entry[] = []; let recordIndex = 0; const reset =()=> recordIndex = 0; const swap =()=> { recordEntry = recordEntryNew; recordEntryNew = [] as Entry[]; }; const proxy =(arg:T)=> { const lookupOld = recordEntry[recordIndex]; if(lookupOld && DeepEqual(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, proxySignalHook as useSignal }; export default {...SignalsParts, signal:proxySignal, useSignal:proxySignalHook};