@@ -81,29 +81,6 @@ const vfjsHelpers = {
8181 } ,
8282 } ) ) ;
8383 } ,
84- vfjsHelperHashString ( string , binary = 62 ) {
85- let integer = 0 ;
86-
87- for ( let i = 0 ; i < string . length ; i ++ ) {
88- const char = string . charCodeAt ( i ) ;
89- integer = ( integer * 33 ) ^ char ; // eslint-disable-line no-bitwise
90- }
91-
92- // Convert int to unsigned to get a positive number
93- integer >>>= 0 ; // eslint-disable-line no-bitwise
94-
95- const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ;
96- const array = [ ] ;
97-
98- // Create an alphanumeric hash of unsigned int
99- while ( integer >= binary ) {
100- const char = integer % binary ;
101- array . push ( chars [ char ] ) ;
102- integer = Math . floor ( integer / binary ) ;
103- }
104-
105- return array . join ( '' ) ;
106- } ,
10784 vfjsHelperCreateComponent ( { children = [ ] , component, props } ) {
10885 // If the component matches one of the local components
10986 // passed in with the `components` prop
@@ -140,25 +117,23 @@ const vfjsHelpers = {
140117 set ( newVfjsModel , key , value ) ;
141118 return newVfjsModel ;
142119 } ,
143- // The level param helps us to differentiate further between fields.
144- // As the same field configuration may be present throughout the ui schema
145- // and thus have the same hash.
146- //
147- // We mediate this by providing the depth level as a second param
148- // which will make the hash unique for every field
149- vfjsHelperGenerateField ( field , level = 0 ) {
120+ /*
121+ * Unique id for every element is generated by simply appending the position index with parentid.
122+ * The parentId is the unique id of parent component ( it can be either a form or a field )
123+ * The id of top most form component is auto generated using Math.random.
124+ * Since id is a function of parentId and element index, we will get consistent , but unique id for each component
125+ */
126+ vfjsHelperGenerateField ( field , parentId ) {
150127 if ( ! field ) {
151128 return false ;
152129 }
153130
154- const { children = [ ] , ...fieldWithoutChildren } = field ;
155- const objString = JSON . stringify ( { fieldWithoutChildren, level } ) ;
156- const id = this . vfjsHelperHashString ( objString ) ;
131+ const { children = [ ] } = field ;
157132
158133 return {
159134 ...field ,
160- id,
161- children : children . map ( ( child , i ) => this . vfjsHelperGenerateField ( child , ( i + 1 ) * ( level + 1 ) ) ) ,
135+ id : parentId ,
136+ children : children . map ( ( child , i ) => this . vfjsHelperGenerateField ( child , ` ${ parentId } - ${ i } ` ) ) ,
162137 } ;
163138 } ,
164139 vfjsHelperChildArrayMapper ( { model, children = [ ] , ...child } , parentModel , index ) {
0 commit comments