|
@@ -112,25 +112,28 @@ export function newOnion({readonly, deltaRegistry, versionRegistry}) {
|
|
|
setHistoryGraph(historyGraph => {
|
|
|
const versionsToAdd: Version[] = [];
|
|
|
const addIfDontHaveYet = version => {
|
|
|
- if (!(historyGraph.nodes.some(n => n.obj === version) || versionsToAdd.includes(version))) {
|
|
|
+ if (!historyGraph.nodes.some(n => n.obj === version) && !versionsToAdd.includes(version)) {
|
|
|
collectVersions(version);
|
|
|
}
|
|
|
}
|
|
|
const collectVersions = version => {
|
|
|
- // first add child, then parent
|
|
|
+ // first add parent, then child
|
|
|
// this prevents infinite recursion when a version explicitly embeds itself.
|
|
|
- versionsToAdd.push(version);
|
|
|
for (const [parent] of version.parents) {
|
|
|
addIfDontHaveYet(parent);
|
|
|
}
|
|
|
for (const {version: guest} of version.embeddings.values()) {
|
|
|
+ if (guest === version) {
|
|
|
+ continue; // special case: self-embedding...
|
|
|
+ }
|
|
|
addIfDontHaveYet(guest);
|
|
|
}
|
|
|
+ versionsToAdd.push(version);
|
|
|
}
|
|
|
for (const v of versions) {
|
|
|
collectVersions(v);
|
|
|
}
|
|
|
- return versionsToAdd.reduceRight((historyGraph, version) => historyGraphReducer(historyGraph, {type: 'addVersion', version}), historyGraph);
|
|
|
+ return versionsToAdd.reduce((historyGraph, version) => historyGraphReducer(historyGraph, {type: 'addVersion', version}), historyGraph);
|
|
|
})
|
|
|
}
|
|
|
// Idempotent
|