Skip to content

Commit 3f64322

Browse files
dajiaohuangjamesgpearce
authored andcommitted
Fix checkpoints when mixed data changes cancel
1 parent 85f2150 commit 3f64322

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎src/checkpoints/index.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ export const createCheckpoints = getCreateFunction(
320320
cellOrValueIsEqual(oldNew[0], newCell) &&
321321
collIsEmpty(mapSet(row, cellId)) &&
322322
collIsEmpty(mapSet(table, rowId)) &&
323-
collIsEmpty(mapSet(cellsDelta, tableId))
323+
collIsEmpty(mapSet(cellsDelta, tableId)) &&
324+
collIsEmpty(valuesDelta)
324325
) {
325326
storeUnchanged();
326327
}
@@ -342,7 +343,8 @@ export const createCheckpoints = getCreateFunction(
342343
oldNew[1] = newValue;
343344
if (
344345
cellOrValueIsEqual(oldNew[0], newValue) &&
345-
collIsEmpty(mapSet(valuesDelta, valueId))
346+
collIsEmpty(mapSet(valuesDelta, valueId)) &&
347+
collIsEmpty(cellsDelta)
346348
) {
347349
storeUnchanged();
348350
}

‎test/unit/core/other/checkpoints.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,37 @@ describe('Basics', () => {
259259
expect(checkpoints.getCheckpointIds()).toEqual([['0'], checkpointId, []]);
260260
});
261261

262+
test.each([true, false])(
263+
'retain mixed changes when cancelling tabular changes: %s',
264+
(cancelTabular) => {
265+
const id0 = checkpoints.getCheckpointIds()[1];
266+
store.setCell('t1', 'r1', 'c1', 1).setValue('v1', 1);
267+
expectChanges(listener, '/', [[id0], undefined, []]);
268+
if (cancelTabular) {
269+
store.delCell('t1', 'r1', 'c1');
270+
} else {
271+
store.delValue('v1');
272+
}
273+
expect(checkpoints.getCheckpointIds()).toEqual([[id0], undefined, []]);
274+
expectNoChanges(listener);
275+
276+
const id1 = checkpoints.addCheckpoint();
277+
expect(id1).not.toEqual(id0);
278+
expectChanges(listener, '/', [[id0], id1, []]);
279+
checkpoints.goBackward();
280+
expect(store.getTables()).toEqual({});
281+
expect(store.getValues()).toEqual({});
282+
expectChanges(listener, '/', [[], id0, [id1]]);
283+
checkpoints.goForward();
284+
expect(store.getTables()).toEqual(
285+
cancelTabular ? {} : {t1: {r1: {c1: 1}}},
286+
);
287+
expect(store.getValues()).toEqual(cancelTabular ? {v1: 1} : {});
288+
expectChanges(listener, '/', [[id0], id1, []]);
289+
expectNoChanges(listener);
290+
},
291+
);
292+
262293
test('listener stats', () => {
263294
listener.listenToCheckpoint('/c0', '0');
264295
expect(checkpoints.getListenerStats()).toEqual({

0 commit comments

Comments
 (0)