@@ -38,6 +38,7 @@ import {
38
38
matchNamePath ,
39
39
setValue ,
40
40
} from './utils/valueUtil' ;
41
+ import { BatchUpdateRef } from './BatchUpdate' ;
41
42
42
43
type InvalidateFieldEntity = { INVALIDATE_NAME_PATH : InternalNamePath } ;
43
44
@@ -119,6 +120,7 @@ export class FormStore {
119
120
setPreserve : this . setPreserve ,
120
121
getInitialValue : this . getInitialValue ,
121
122
registerWatch : this . registerWatch ,
123
+ setBatchUpdate : this . setBatchUpdate ,
122
124
} ;
123
125
}
124
126
@@ -214,6 +216,27 @@ export class FormStore {
214
216
}
215
217
} ;
216
218
219
+ private notifyWatchNamePathList : InternalNamePath [ ] = [ ] ;
220
+ private batchNotifyWatch = ( namePath : InternalNamePath ) => {
221
+ this . notifyWatchNamePathList . push ( namePath ) ;
222
+ this . batch ( 'notifyWatch' , ( ) => {
223
+ this . notifyWatch ( this . notifyWatchNamePathList ) ;
224
+ this . notifyWatchNamePathList = [ ] ;
225
+ } ) ;
226
+ } ;
227
+
228
+ // ============================= Batch ============================
229
+ private batchUpdateRef : React . RefObject < BatchUpdateRef > ;
230
+
231
+ private setBatchUpdate = ( batchUpdate : React . RefObject < BatchUpdateRef > ) => {
232
+ this . batchUpdateRef = batchUpdate ;
233
+ } ;
234
+
235
+ // Batch call the task, only last will be called
236
+ private batch = ( key : string , callback : VoidFunction ) => {
237
+ this . batchUpdateRef . current ?. batch ( key , callback ) ;
238
+ } ;
239
+
217
240
// ========================== Dev Warning =========================
218
241
private timeoutId : any = null ;
219
242
@@ -682,7 +705,7 @@ export class FormStore {
682
705
}
683
706
}
684
707
685
- this . notifyWatch ( [ namePath ] ) ;
708
+ this . batchNotifyWatch ( namePath ) ;
686
709
} ;
687
710
} ;
688
711
0 commit comments