@@ -38,6 +38,7 @@ import {
3838 matchNamePath ,
3939 setValue ,
4040} from './utils/valueUtil' ;
41+ import { BatchUpdateRef } from './BatchUpdate' ;
4142
4243type InvalidateFieldEntity = { INVALIDATE_NAME_PATH : InternalNamePath } ;
4344
@@ -119,6 +120,7 @@ export class FormStore {
119120 setPreserve : this . setPreserve ,
120121 getInitialValue : this . getInitialValue ,
121122 registerWatch : this . registerWatch ,
123+ setBatchUpdate : this . setBatchUpdate ,
122124 } ;
123125 }
124126
@@ -214,6 +216,27 @@ export class FormStore {
214216 }
215217 } ;
216218
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+
217240 // ========================== Dev Warning =========================
218241 private timeoutId : any = null ;
219242
@@ -682,7 +705,7 @@ export class FormStore {
682705 }
683706 }
684707
685- this . notifyWatch ( [ namePath ] ) ;
708+ this . batchNotifyWatch ( namePath ) ;
686709 } ;
687710 } ;
688711
0 commit comments