Skip to content

Commit

Permalink
Fix issues when restoring from saved backup
Browse files Browse the repository at this point in the history
(re: #1489)

Our `load` function was not working correctly, by considering the base state
instead of the previous state when calling `updateCalculated` to fix caches.

This changes the `load` function to do basically the same thing as the
`replace`/`revert` functions that get called during the normal course of editing.
  • Loading branch information
bhousel committed Jan 14, 2025
1 parent 513589b commit 3b1c85d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions modules/core/lib/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class Graph {

/**
* revert
* Revert an Entity back to whatver state it had in the base graph
* Revert an Entity back to whatever state it had in the base graph
* @param entityID The entityID of the Entity to revert
* @return A new Graph
*/
Expand Down Expand Up @@ -492,18 +492,16 @@ export class Graph {
* load
* Loads new Entities into the local Graph, obliterating any existing Entities.
* Used when restoring history or entering/leaving walkthrough.
* This basically does the same thing as `replace`/`remove`, but without creating a new Graph.
* @param entities `Object (entityID -> Entity)`
* @return this Graph
*/
load(entities) {
const base = this._base;
const local = this._local;
local.entities = new Map();

for (const [entityID, entity] of Object.entries(entities)) {
const original = base.entities.get(entityID); // likely undefined, but may as well check
local.entities.set(entityID, entity);
this._updateCalculated(original, entity);
const current = this.hasEntity(entityID);
const replacement = entity || undefined;
this._updateCalculated(current, replacement);
this._local.entities.set(entityID, replacement);
}

return this;
Expand Down

0 comments on commit 3b1c85d

Please sign in to comment.