Skip to content

Commit 637b2c7

Browse files
fix(data): make undoMany remove tracking changes in changeState (#2346) (#2352)
Closes #2346
1 parent f09df95 commit 637b2c7

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

modules/data/spec/reducers/entity-change-tracker-base.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,22 @@ describe('EntityChangeTrackerBase', () => {
649649
});
650650

651651
describe('#undoOne', () => {
652+
it('should clear one tracked change', () => {
653+
let { collection, deletedEntity } = createTestTrackedEntities();
654+
655+
expect(Object.keys(collection.changeState).length).toBe(
656+
3,
657+
'tracking 3 entities'
658+
);
659+
660+
collection = tracker.undoOne(deletedEntity as Hero, collection);
661+
662+
expect(Object.keys(collection.changeState).length).toBe(
663+
2,
664+
'tracking 2 entities'
665+
);
666+
});
667+
652668
it('should restore the collection to the pre-change state for the given entity', () => {
653669
// tslint:disable-next-line:prefer-const
654670
let {
@@ -698,6 +714,32 @@ describe('EntityChangeTrackerBase', () => {
698714
});
699715

700716
describe('#undoMany', () => {
717+
it('should clear many tracked changes', () => {
718+
// tslint:disable-next-line:prefer-const
719+
let {
720+
collection,
721+
addedEntity,
722+
deletedEntity,
723+
preUpdatedEntity,
724+
updatedEntity,
725+
} = createTestTrackedEntities();
726+
727+
expect(Object.keys(collection.changeState).length).toBe(
728+
3,
729+
'tracking 3 entities'
730+
);
731+
732+
collection = tracker.undoMany(
733+
[addedEntity, deletedEntity, updatedEntity],
734+
collection
735+
);
736+
737+
expect(Object.keys(collection.changeState).length).toBe(
738+
0,
739+
'tracking 2 entities'
740+
);
741+
});
742+
701743
it('should restore the collection to the pre-change state for the given entities', () => {
702744
// tslint:disable-next-line:prefer-const
703745
let {

modules/data/src/reducers/entity-change-tracker-base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ export class EntityChangeTrackerBase<T> implements EntityChangeTracker<T> {
687687
didMutate = true;
688688
}
689689
delete chgState[id]; // clear tracking of this entity
690+
acc.changeState = chgState;
690691
switch (change.changeType) {
691692
case ChangeType.Added:
692693
acc.remove.push(id);
@@ -714,7 +715,7 @@ export class EntityChangeTrackerBase<T> implements EntityChangeTracker<T> {
714715

715716
collection = this.adapter.removeMany(remove as string[], collection);
716717
collection = this.adapter.upsertMany(upsert, collection);
717-
return didMutate ? collection : { ...collection, changeState };
718+
return didMutate ? { ...collection, changeState } : collection;
718719
}
719720

720721
/**

0 commit comments

Comments
 (0)