@@ -32,6 +32,8 @@ import {
32
32
setValues ,
33
33
} from './utils/valueUtil' ;
34
34
35
+ type InvalidateFieldEntity = { INVALIDATE_NAME_PATH : InternalNamePath } ;
36
+
35
37
interface UpdateAction {
36
38
type : 'updateValue' ;
37
39
namePath : InternalNamePath ;
@@ -162,38 +164,42 @@ export class FormStore {
162
164
return cache ;
163
165
} ;
164
166
165
- private getFieldEntitiesForNamePathList = ( nameList ?: NamePath [ ] ) => {
167
+ private getFieldEntitiesForNamePathList = (
168
+ nameList ?: NamePath [ ] ,
169
+ ) : ( FieldEntity | InvalidateFieldEntity ) [ ] => {
166
170
if ( ! nameList ) {
167
171
return this . getFieldEntities ( true ) ;
168
172
}
169
173
const cache = this . getFieldsMap ( true ) ;
170
174
return nameList . map ( name => {
171
175
const namePath = getNamePath ( name ) ;
172
- return cache . get ( namePath ) ;
176
+ return cache . get ( namePath ) || { INVALIDATE_NAME_PATH : getNamePath ( name ) } ;
173
177
} ) ;
174
178
} ;
175
179
176
- private getFieldsValue = (
177
- nameList ?: NamePath [ ] ,
178
- filterFunc ?: ( meta : Meta ) => boolean ,
179
- ) => {
180
+ private getFieldsValue = ( nameList ?: NamePath [ ] | true , filterFunc ?: ( meta : Meta ) => boolean ) => {
180
181
this . warningUnhooked ( ) ;
181
182
182
- if ( ! nameList && ! filterFunc ) {
183
+ if ( nameList === true && ! filterFunc ) {
183
184
return this . store ;
184
185
}
185
- if ( ! filterFunc ) {
186
- return cloneByNamePathList ( this . store , nameList . map ( getNamePath ) ) ;
187
- }
188
186
189
- const fieldEntities = this . getFieldEntitiesForNamePathList ( nameList ) ;
187
+ const fieldEntities = this . getFieldEntitiesForNamePathList (
188
+ Array . isArray ( nameList ) ? nameList : null ,
189
+ ) ;
190
190
191
191
const filteredNameList : NamePath [ ] = [ ] ;
192
- fieldEntities . forEach ( ( field : FieldEntity ) => {
193
- const namePath = field . getNamePath ( ) ;
194
- const meta = field . getMeta ( ) ;
195
- if ( filterFunc ( meta ) ) {
192
+ fieldEntities . forEach ( ( entity : FieldEntity | InvalidateFieldEntity ) => {
193
+ const namePath =
194
+ 'INVALIDATE_NAME_PATH' in entity ? entity . INVALIDATE_NAME_PATH : entity . getNamePath ( ) ;
195
+
196
+ if ( ! filterFunc ) {
196
197
filteredNameList . push ( namePath ) ;
198
+ } else {
199
+ const meta : Meta = 'getMeta' in entity ? entity . getMeta ( ) : null ;
200
+ if ( filterFunc ( meta ) ) {
201
+ filteredNameList . push ( namePath ) ;
202
+ }
197
203
}
198
204
} ) ;
199
205
@@ -213,7 +219,7 @@ export class FormStore {
213
219
const fieldEntities = this . getFieldEntitiesForNamePathList ( nameList ) ;
214
220
215
221
return fieldEntities . map ( ( entity , index ) => {
216
- if ( entity ) {
222
+ if ( entity && ! ( 'INVALIDATE_NAME_PATH' in entity ) ) {
217
223
return {
218
224
name : entity . getNamePath ( ) ,
219
225
errors : entity . getErrors ( ) ,
0 commit comments