add support for init func arg

This commit is contained in:
Seth Trowbridge 2023-06-19 13:31:22 -04:00
parent 68503424e6
commit 19cc54dcea
2 changed files with 9 additions and 3 deletions

View File

@ -102,10 +102,10 @@ const ProxyState =(argNew:StateType)=>
}; };
type Storelike = Record<string, string> type Storelike = Record<string, string>
const ProxyReducer =(inReducer:(inState:Storelike, inAction:string)=>Storelike, inState:Storelike)=> const ProxyReducer =(inReducer:(inState:Storelike, inAction:string)=>Storelike, inState:Storelike, inInit?:(inState:Storelike)=>Storelike)=>
{ {
const check = MapIndex(HMR.statesOld, HMR.statesNew.size); const check = MapIndex(HMR.statesOld, HMR.statesNew.size);
const argOld = check ? check[1].state : inState; const argOld = check ? check[1].state : (inInit ? inInit(inState) : inState);
const intercept =(inInterceptState:Storelike, inInterceptAction:string)=> const intercept =(inInterceptState:Storelike, inInterceptAction:string)=>
{ {

View File

@ -24,10 +24,16 @@ const reducer =(inState:Store, inAction:number)=>
return {...inState, age:inState.age+inAction}; return {...inState, age:inState.age+inAction};
} }
const builder =(inState:Store):Store=>
{
inState.age = 100;
return inState;
}
export default ()=> export default ()=>
{ {
const [Store, Dispatch] = React.useReducer(reducer, {name:"seth", age:24} as Store) const [Store, Dispatch] = React.useReducer(reducer, {name:"seth", age:24} as Store, builder)
return <CTXString.Provider value="intradestink"> return <CTXString.Provider value="intradestink">
<div> <div>
<h1>Title!</h1> <h1>Title!</h1>