File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change 1- export function memoize < F extends ( ... args : ( string | number | boolean ) [ ] ) => any > (
2- fn : F ,
3- options : {
4- argsLength : number ;
1+ export function memoize < Args extends ( number | boolean | string ) [ ] , R > (
2+ fn : ( ... args : Args ) => R ,
3+ options ? : {
4+ argsLength ? : number ;
55 }
6- ) : F {
7- const cache : Record < string , ReturnType < F > > = { } ;
6+ ) : ( ... args : Args ) => R {
7+ const cache : Record < string , R > = { } ;
88
9- const { argsLength } = options ;
9+ const { argsLength = fn . length } = options ?? { } ;
1010
11- return ( ( ...args : Parameters < F > ) => {
11+ return ( ( ...args : Args ) => {
1212 const key = JSON . stringify ( args . slice ( 0 , argsLength ) . join ( "-sIs9sAslOdeWlEdIos3-" ) ) ;
1313
1414 console . log ( key , JSON . stringify ( { argsLength, args } ) ) ;
Original file line number Diff line number Diff line change @@ -36,14 +36,14 @@ export function useCallbackFactory<
3636 id < Out > ( ( ...factoryArgs ) => {
3737 if ( memoizedRef . current === undefined ) {
3838 memoizedRef . current = memoize (
39- ( ( ...factoryArgs : FactoryArgs ) =>
39+ ( ...factoryArgs : FactoryArgs ) =>
4040 ( ...args : Args ) =>
41- callbackRef . current ( factoryArgs , args ) ) as any ,
41+ callbackRef . current ( factoryArgs , args ) ,
4242 { "argsLength" : factoryArgs . length }
4343 ) ;
4444 }
4545
46- return ( memoizedRef . current as any ) ( ...factoryArgs ) ;
46+ return memoizedRef . current ( ...factoryArgs ) ;
4747 } )
4848 ) [ 0 ] ;
4949}
You can’t perform that action at this time.
0 commit comments