Skip to content

Commit

Permalink
Make data save functions read only (#4871)
Browse files Browse the repository at this point in the history
Instead of calling removeConnections, we now simply ignore
cross-scope connections.

Remove redundant call to update

The save functions should be strictly read-only and should not
change the state of the simulator. This is especially important
given the existence of auto-save. We don't want simulator state
to change every 3 seconds when auto-save is called even when the
user did not change the state.

For most circuits this is not a problem, but for some circuits
where a section of the circuit has multiple legal values, the
circuit should not change to the other legal value without a
driving signal. But a force-reset update might cause such a
state change. Earlier such an update call was a part of the save
flow and was called with autosave(), this should not be a problem
after this commit.
  • Loading branch information
gr455 committed Apr 4, 2024
1 parent efa65c5 commit 9f6897a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 0 additions & 6 deletions simulator/src/data/backupCircuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export function checkIfBackup(scope) {
}

export function backUp(scope = globalScope) {
// Disconnection of subcircuits are needed because these are the connections between nodes
// in current scope and those in the subcircuit's scope
for (let i = 0; i < scope.SubCircuit.length; i++) { scope.SubCircuit[i].removeConnections(); }

var data = {};

Expand Down Expand Up @@ -51,9 +48,6 @@ export function backUp(scope = globalScope) {
data.nodes = [];
for (let i = 0; i < scope.nodes.length; i++) { data.nodes.push(scope.allNodes.indexOf(scope.nodes[i])); }

// Restoring the connections
for (let i = 0; i < scope.SubCircuit.length; i++) { scope.SubCircuit[i].makeConnections(); }

return data;
}

Expand Down
7 changes: 6 additions & 1 deletion simulator/src/data/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export function generateSaveData(name, setName = true) {
}

completed[id] = true;
update(scopeList[id]); // For any pending integrity checks on subcircuits

// Removed: no such check is required. saveScope should be strictly read only and
// should not change state
// update might change state.

// update(scopeList[id]); // For any pending integrity checks on subcircuits
data.scopes.push(backUp(scopeList[id]));
}

Expand Down
3 changes: 3 additions & 0 deletions simulator/src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ export default class Node {
connections: [],
};
for (var i = 0; i < this.connections.length; i++) {
// For connections from scope.Subcircuit.node to localscope.input/output.node
// these connections should be ignored while saving.
if (this.connections[i].scope != this.scope) continue;
data.connections.push(findNode(this.connections[i]));
}
return data;
Expand Down

0 comments on commit 9f6897a

Please sign in to comment.