@@ -9,31 +9,33 @@ const createDecorator = (...calculations: Calculation[]): Decorator => (
99 let previousValues = { }
1010 const unsubscribe = form . subscribe (
1111 ( { values } ) => {
12- const runUpdates = ( field : string , updates : Updates ) => {
13- const next = getIn ( values , field )
14- const previous = getIn ( previousValues , field )
15- if ( next !== previous ) {
16- Object . keys ( updates ) . forEach ( destField => {
17- const update = updates [ destField ]
18- form . change ( destField , update ( next , values ) )
19- } )
20- }
21- }
22- const fields = form . getRegisteredFields ( )
23- calculations . forEach ( ( { field, updates } ) => {
24- if ( typeof field === 'string' ) {
25- runUpdates ( field , updates )
26- } else {
27- // field is a regex
28- const regex = ( field : RegExp )
29- fields . forEach ( fieldName => {
30- if ( regex . test ( fieldName ) ) {
31- runUpdates ( fieldName , updates )
32- }
33- } )
12+ form . batch ( ( ) => {
13+ const runUpdates = ( field : string , updates : Updates ) => {
14+ const next = getIn ( values , field )
15+ const previous = getIn ( previousValues , field )
16+ if ( next !== previous ) {
17+ Object . keys ( updates ) . forEach ( destField => {
18+ const update = updates [ destField ]
19+ form . change ( destField , update ( next , values ) )
20+ } )
21+ }
3422 }
23+ const fields = form . getRegisteredFields ( )
24+ calculations . forEach ( ( { field, updates } ) => {
25+ if ( typeof field === 'string' ) {
26+ runUpdates ( field , updates )
27+ } else {
28+ // field is a regex
29+ const regex = ( field : RegExp )
30+ fields . forEach ( fieldName => {
31+ if ( regex . test ( fieldName ) ) {
32+ runUpdates ( fieldName , updates )
33+ }
34+ } )
35+ }
36+ } )
37+ previousValues = values
3538 } )
36- previousValues = values
3739 } ,
3840 { values : true }
3941 )
0 commit comments