-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsquash-history.js
46 lines (40 loc) · 1.27 KB
/
squash-history.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
export function squashHistory({ opsByID, cache, stepsToDelete }) {
// TODO: what does it mean to delete history entry without deleting parent?
// should it just implicitly delete isolated parents?
let computeNeeded = false;
// eslint-disable-next-line no-unused-vars
const dependentOpEntries = Object.entries(opsByID).filter(([id, op]) =>
stepsToDelete.includes(id)
);
const dependencyReplacements = dependentOpEntries.map(([id, oldOp]) => {
let value = cache[id];
// overcomplicated: this doesn't need to be in here
// can just use cache; cache can reference same objects, so it's not using much extra memory
// if (!value) {
// if (oldOp.type === "array" || oldOp.type === "data") {
// value = oldOp.data;
// }
// }
if (value) {
const newOp = { value };
newOp.type = newOp.value instanceof Array ? "array" : "data";
return { id, oldOp, newOp };
} else {
computeNeeded = true;
}
});
if (computeNeeded) {
return { computeNeeded: true };
}
// return dependencyReplacements;
for (const { id /*, oldOp, newOp*/ } of dependencyReplacements) {
delete opsByID[id];
delete cache[id];
}
return { computeNeeded: false };
// TODO: non-destructive (DDDBD), prereq: meta-history
// return {
// permanentlyDelete: function () {
// }
// };
}