hmr signal hook!
This commit is contained in:
parent
b0f87d20c5
commit
7824b47634
@ -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")})
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import * as ReactParts from "react-original";
|
import * as ReactParts from "react-original";
|
||||||
import { Process } from "./hmr-listen.tsx";
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
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 recordEntry:Entry<T>[] = [];
|
||||||
|
let recordEntryNew:Entry<T>[] = [];
|
||||||
let recordIndex = 0;
|
let recordIndex = 0;
|
||||||
export const recordIndexReset =()=> recordIndex = 0;
|
const reset =()=> recordIndex = 0;
|
||||||
export const recordEntrySwap =()=>
|
const swap =()=>
|
||||||
{
|
{
|
||||||
recordEntry = recordEntryNew;
|
recordEntry = recordEntryNew;
|
||||||
recordEntryNew = [] as Entry[];
|
recordEntryNew = [] as Entry<T>[];
|
||||||
};
|
};
|
||||||
const proxySignal =(arg)=>
|
const proxy =(arg:T)=>
|
||||||
{
|
{
|
||||||
const lookupOld = recordEntry[recordIndex];
|
const lookupOld = recordEntry[recordIndex];
|
||||||
if(lookupOld && lookupOld[1] === arg)
|
if(lookupOld && lookupOld[1] === arg)
|
||||||
@ -22,16 +24,23 @@ const proxySignal =(arg)=>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const sig = SignalsParts.signal(arg);
|
const sig = inFunc(arg);
|
||||||
recordEntryNew[recordIndex] = [sig, arg];
|
recordEntryNew[recordIndex] = [sig, arg];
|
||||||
recordEntry[recordIndex] = [sig, arg];
|
recordEntry[recordIndex] = [sig, arg];
|
||||||
recordIndex++;
|
recordIndex++;
|
||||||
return sig;
|
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};
|
|
Loading…
Reference in New Issue
Block a user