File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,20 @@ export interface WeakMapMemoizeOptions<Result = any> {
9696  resultEqualityCheck ?: EqualityFn < Result > 
9797} 
9898
99+ /** 
100+  * Derefences the argument if it is a Ref. Else if it is a value already, return it. 
101+  * 
102+  * @param  r - the object to maybe deref 
103+  * @returns  The derefenced value if the argument is a Ref, else the argument value itself. 
104+  */ 
105+ function  maybeDeref ( r : any )  { 
106+   if  ( r  instanceof  Ref )  { 
107+     return  r . deref ( ) 
108+   } 
109+ 
110+   return  r 
111+ } 
112+ 
99113/** 
100114 * Creates a tree of `WeakMap`-based cache nodes based on the identity of the 
101115 * arguments it's been called with (in this case, the extracted values from your input selectors). 
@@ -229,7 +243,8 @@ export function weakMapMemoize<Func extends AnyFunction>(
229243      resultsCount ++ 
230244
231245      if  ( resultEqualityCheck )  { 
232-         const  lastResultValue  =  lastResult ?. deref ?.( )  ??  lastResult 
246+         // Deref lastResult if it is a Ref 
247+         const  lastResultValue  =  maybeDeref ( lastResult ) 
233248
234249        if  ( 
235250          lastResultValue  !=  null  && 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments