@@ -55,6 +55,20 @@ import {
55
55
ReadOnlyProperties ,
56
56
} from './constants'
57
57
58
+ const hasOwnProperty = Object . prototype . hasOwnProperty
59
+
60
+ const notify = (
61
+ target : Form | Field ,
62
+ formType : LifeCycleTypes ,
63
+ fieldType : LifeCycleTypes
64
+ ) => {
65
+ if ( isForm ( target ) ) {
66
+ target . notify ( formType )
67
+ } else {
68
+ target . notify ( fieldType )
69
+ }
70
+ }
71
+
58
72
export const isHTMLInputEvent = ( event : any , stopPropagation = true ) => {
59
73
if ( event ?. target ) {
60
74
if ( isValid ( event . target . value ) || isValid ( event . target . checked ) )
@@ -86,23 +100,25 @@ export const getValuesFromEvent = (args: any[]) => {
86
100
87
101
export const buildFieldPath = ( field : GeneralField ) => {
88
102
let prevArray = false
89
- return field . address . reduce ( ( path : FormPath , key : string , index : number ) => {
90
- const currentPath = path . concat ( [ key ] )
91
- const currentAddress = field . address . slice ( 0 , index + 1 )
92
- const current = field . form . fields [ currentAddress . toString ( ) ]
103
+ const fields = field . form . fields
104
+ const segments = field . address . segments
105
+ const path = segments . reduce ( ( path : string [ ] , key : string , index : number ) => {
106
+ const currentPath = path . concat ( key )
107
+ const currentAddress = segments . slice ( 0 , index + 1 )
108
+ const current = fields [ currentAddress . join ( '.' ) ]
93
109
if ( prevArray ) {
94
110
prevArray = false
95
111
return path
96
112
}
97
- if ( index >= field . address . length - 1 ) {
113
+ if ( index >= segments . length - 1 ) {
98
114
if ( isVoidField ( field ) ) {
99
115
return currentPath
100
116
}
101
117
return currentPath
102
118
}
103
119
if ( isVoidField ( current ) ) {
104
- const parentAddress = field . address . slice ( 0 , index )
105
- const parent = field . form . fields [ parentAddress . toString ( ) ]
120
+ const parentAddress = segments . slice ( 0 , index )
121
+ const parent = fields [ parentAddress . join ( '.' ) ]
106
122
if ( isArrayField ( parent ) && isNumberLike ( key ) ) {
107
123
prevArray = true
108
124
return currentPath
@@ -112,7 +128,8 @@ export const buildFieldPath = (field: GeneralField) => {
112
128
prevArray = false
113
129
}
114
130
return currentPath
115
- } , new FormPath ( '' ) )
131
+ } , [ ] )
132
+ return new FormPath ( path )
116
133
}
117
134
118
135
export const buildNodeIndexes = (
@@ -121,7 +138,7 @@ export const buildNodeIndexes = (
121
138
) => {
122
139
field . address = FormPath . parse ( address )
123
140
field . path = buildFieldPath ( field )
124
- field . form . indexes . set ( field . path . toString ( ) , field . address . toString ( ) )
141
+ field . form . indexes [ field . path . toString ( ) ] = field . address . toString ( )
125
142
return field
126
143
}
127
144
@@ -277,8 +294,6 @@ export const validateToFeedbacks = async (
277
294
return results
278
295
}
279
296
280
- const hasOwnProperty = Object . prototype . hasOwnProperty
281
-
282
297
export const setValidatorRule = ( field : Field , name : string , value : any ) => {
283
298
if ( ! isValid ( value ) ) return
284
299
const hasRule = parseValidatorDescriptions ( field . validator ) . some (
@@ -666,6 +681,7 @@ export const createBatchStateSetter = (form: Form) => {
666
681
}
667
682
} )
668
683
}
684
+
669
685
export const createBatchStateGetter = ( form : Form ) => {
670
686
return ( pattern : FieldMatchPattern , payload ?: any ) => {
671
687
if ( isQuery ( pattern ) ) {
@@ -710,18 +726,6 @@ export const triggerFormValuesChange = (form: Form, change: DataChange) => {
710
726
}
711
727
}
712
728
713
- const notify = (
714
- target : Form | Field ,
715
- formType : LifeCycleTypes ,
716
- fieldType : LifeCycleTypes
717
- ) => {
718
- if ( isForm ( target ) ) {
719
- target . notify ( formType )
720
- } else {
721
- target . notify ( fieldType )
722
- }
723
- }
724
-
725
729
export const setValidating = ( target : Form | Field , validating : boolean ) => {
726
730
clearTimeout ( target . requests . validate )
727
731
if ( validating ) {
0 commit comments