11import { type Control , type FieldValues , get , set } from 'react-hook-form' ;
22
3- import type { LensesStorage } from './LensesStorage' ;
3+ import type { LensesStorage , LensesStorageComplexKey } from './LensesStorage' ;
44import type { Lens } from './types' ;
55
66export interface LensCoreInteropBinding < T extends FieldValues > {
@@ -18,9 +18,10 @@ export class LensCore<T extends FieldValues> {
1818 public path : string ;
1919 public cache ?: LensesStorage < T > | undefined ;
2020
21- private isArrayItemReflection ?: boolean ;
22- private override ?: Record < string , LensCore < T > > | [ Record < string , LensCore < T > > ] ;
23- private interopCache ?: LensCoreInteropBinding < T > ;
21+ protected isArrayItemReflection ?: boolean ;
22+ protected override ?: Record < string , LensCore < T > > | [ Record < string , LensCore < T > > ] ;
23+ protected interopCache ?: LensCoreInteropBinding < T > ;
24+ protected reflectedKey ?: LensesStorageComplexKey ;
2425
2526 constructor ( control : Control < T > , path : string , cache ?: LensesStorage < T > | undefined ) {
2627 this . control = control ;
@@ -39,7 +40,7 @@ export class LensCore<T extends FieldValues> {
3940 const propString = prop . toString ( ) ;
4041 const nestedPath = this . path ? `${ this . path } .${ propString } ` : propString ;
4142
42- const fromCache = this . cache ?. get ( nestedPath ) ;
43+ const fromCache = this . cache ?. get ( nestedPath , this . reflectedKey ) ;
4344
4445 if ( fromCache ) {
4546 return fromCache ;
@@ -112,11 +113,13 @@ export class LensCore<T extends FieldValues> {
112113 const result = new LensCore ( this . control , this . path , this . cache ) ;
113114 template . path = '' ;
114115 result . override = getter ( dictionary , template ) ;
116+ result . reflectedKey = getter ;
115117 this . cache ?. set ( result , this . path , getter ) ;
116118 return result ;
117119 } else {
118120 template . override = override ;
119121 template . path = this . path ;
122+ template . reflectedKey = getter ;
120123 this . cache ?. set ( template , this . path , getter ) ;
121124 return template ;
122125 }
@@ -147,7 +150,7 @@ export class LensCore<T extends FieldValues> {
147150 return this . interopCache ;
148151 }
149152
150- private getTransformer ( value : unknown ) : unknown {
153+ protected getTransformer ( value : unknown ) : unknown {
151154 const [ template ] = Array . isArray ( this . override ) ? this . override : [ this . override ] ;
152155
153156 if ( ! value || ! template ) {
@@ -170,7 +173,7 @@ export class LensCore<T extends FieldValues> {
170173 return newValue ;
171174 }
172175
173- private setTransformer ( value : unknown ) : unknown {
176+ protected setTransformer ( value : unknown ) : unknown {
174177 const [ template ] = Array . isArray ( this . override ) ? this . override : [ this . override ] ;
175178
176179 if ( ! value || ! template ) {
0 commit comments