Do not over-prune var data cache (#1198)

* Remove unused variables and imports

* Simplify conditional

* Fix typo

* Do not overprune var data cache

There is a bug in how the universe and world gene sets are constructed
and passed to `ControlsHelpers.pruneVarDataCache` that causes the var
data cache to be over-pruned. This commit fixes the issue.

Consider the following example from the node console:

```
❯ node
Welcome to Node.js v13.5.0.
Type ".help" for more information.
> new Set([1], [2], [3])
Set(1) { 1 }
```

What we really want is the set `Set(3) { 1, 2, 3 }`, which can be
constructed as:

```
> new Set([].concat([1], [2], [3]))
Set(3) { 1, 2, 3 }
```
This commit is contained in:
Matt Weiden
2020-03-05 18:04:14 -08:00
committed by GitHub
parent bddf66d62a
commit bdd69160e2
9 changed files with 13 additions and 22 deletions
-1
View File
@@ -1,7 +1,6 @@
// jshint esversion: 6
import _ from "lodash";
import * as globals from "../globals";
import { subsetAndResetGeneLists } from "../util/stateManager/controlsHelpers";
const Controls = (
+3 -3
View File
@@ -221,15 +221,15 @@ const Undoable = (reducer, undoableKeys, options = {}) => {
const aType = action.type;
switch (aType) {
case "@@undoable/undo": {
return undo(currentState, action);
return undo(currentState);
}
case "@@undoable/redo": {
return redo(currentState, action);
return redo(currentState);
}
case "@@undoable/clear": {
return clear(currentState, action);
return clear(currentState);
}
default: {
+1 -1
View File
@@ -145,7 +145,7 @@ Signature: (fsm, event, from) => undoableAction
const onFsmError = (fsm, event, from) => {
console.error(`FSM error [event: "${event}", state: "${from}"]`, fsm);
// In production, try to recover gracefully if we have unexpected state
return clear(fsm);
return clear();
};
/*
+1 -3
View File
@@ -62,9 +62,7 @@ const Universe = (state = null, action, nextSharedState, prevSharedState) => {
const { userDefinedGenes, diffexpGenes } = prevSharedState;
const allTheGenesWeNeed = [
...new Set(
userDefinedGenes,
diffexpGenes,
Object.keys(action.expressionData)
[userDefinedGenes, diffexpGenes, Object.keys(action.expressionData)].filter(ele => ele).flat()
)
];
varData = ControlsHelpers.pruneVarDataCache(varData, allTheGenesWeNeed);
+2 -7
View File
@@ -101,15 +101,10 @@ const WorldReducer = (
const { userDefinedGenes, diffexpGenes } = prevSharedState;
const allTheGenesWeNeed = [
...new Set(
userDefinedGenes,
diffexpGenes,
Object.keys(action.expressionData)
[userDefinedGenes, diffexpGenes, Object.keys(action.expressionData)].filter(ele => ele).flat()
)
];
unclippedVarData = ControlsHelpers.pruneVarDataCache(
unclippedVarData,
allTheGenesWeNeed
);
unclippedVarData = ControlsHelpers.pruneVarDataCache(unclippedVarData, allTheGenesWeNeed);
// at this point, we have the unclipped data in unclippedVarData.
// Now create clipped.