@@ -24,7 +24,8 @@ import {
24
24
remove as lodashRemove ,
25
25
uniq ,
26
26
first ,
27
- some
27
+ some ,
28
+ partition
28
29
} from 'lodash' ;
29
30
import { Field , FieldSpec } from './Field' ;
30
31
import { parseFilter } from './filter/Utils' ;
@@ -590,7 +591,8 @@ export class Store extends HoistBase {
590
591
data : updatedData ,
591
592
parent : currentRec . parent ,
592
593
store : currentRec . store ,
593
- committedData : currentRec . committedData
594
+ committedData : currentRec . committedData ,
595
+ isSummary : currentRec . isSummary
594
596
} ) ;
595
597
596
598
if ( ! equal ( currentRec . data , updatedRec . data ) ) {
@@ -643,13 +645,20 @@ export class Store extends HoistBase {
643
645
records = castArray ( records ) ;
644
646
if ( isEmpty ( records ) ) return ;
645
647
646
- const recs = records . map ( it => ( it instanceof StoreRecord ? it : this . getOrThrow ( it ) ) ) ;
648
+ const recs = records . map ( it => ( it instanceof StoreRecord ? it : this . getOrThrow ( it ) ) ) ,
649
+ [ summaryRecsToRevert , recsToRevert ] = partition ( recs , 'isSummary' ) ;
647
650
648
- this . _current = this . _current
649
- . withTransaction ( { update : recs . map ( r => this . getCommittedOrThrow ( r . id ) ) } )
650
- . normalize ( this . _committed ) ;
651
+ if ( ! isEmpty ( summaryRecsToRevert ) ) {
652
+ this . revertSummaryRecords ( summaryRecsToRevert ) ;
653
+ }
651
654
652
- this . rebuildFiltered ( ) ;
655
+ if ( ! isEmpty ( recsToRevert ) ) {
656
+ this . _current = this . _current
657
+ . withTransaction ( { update : recsToRevert . map ( r => this . getCommittedOrThrow ( r . id ) ) } )
658
+ . normalize ( this . _committed ) ;
659
+
660
+ this . rebuildFiltered ( ) ;
661
+ }
653
662
}
654
663
655
664
/**
@@ -662,6 +671,7 @@ export class Store extends HoistBase {
662
671
@action
663
672
revert ( ) {
664
673
this . _current = this . _committed ;
674
+ if ( this . summaryRecords ) this . revertSummaryRecords ( this . summaryRecords ) ;
665
675
this . rebuildFiltered ( ) ;
666
676
}
667
677
@@ -1119,6 +1129,24 @@ export class Store extends HoistBase {
1119
1129
'idSpec should be either a name of a field, or a function to generate an id.'
1120
1130
) ;
1121
1131
}
1132
+
1133
+ @action
1134
+ private revertSummaryRecords ( records : StoreRecord [ ] ) {
1135
+ this . summaryRecords = this . summaryRecords . map ( summaryRec => {
1136
+ const recToRevert = records . find ( it => it . id === summaryRec . id ) ;
1137
+ if ( ! recToRevert ) return summaryRec ;
1138
+
1139
+ const ret = new StoreRecord ( {
1140
+ id : recToRevert . id ,
1141
+ raw : recToRevert . raw ,
1142
+ data : { ...recToRevert . committedData } ,
1143
+ store : this ,
1144
+ isSummary : true
1145
+ } ) ;
1146
+ ret . finalize ( ) ;
1147
+ return ret ;
1148
+ } ) ;
1149
+ }
1122
1150
}
1123
1151
1124
1152
//---------------------------------------------------------------------
0 commit comments