Skip to content

Commit

Permalink
controls/color-by: Debounce position updates so that typing is smooth
Browse files Browse the repository at this point in the history
This avoids triggering a new state on every keypress in a short
sequence, which is not only slow but inconsistent with expectations that
intermediate colorations are shown while, for example, backspacing a
position input to delete it.

400ms seemed about right in my testing (300ms was too quick for most
typists, 500ms seemed sluggish), but that value may want to be adjusted.
  • Loading branch information
tsibley committed Nov 16, 2018
1 parent ec6b009 commit 1b46f72
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/controls/color-by.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import PropTypes from 'prop-types';
import { connect } from "react-redux";
import Select from "react-select";
import { debounce } from "lodash";
import { sidebarField } from "../../globalStyles";
import { controlsWidth, colorByMenuPreferredOrdering } from "../../util/globals";
import { changeColorBy } from "../../actions/colors";
Expand Down Expand Up @@ -92,16 +93,23 @@ class ColorBy extends React.Component {
});

if (genotype) {
analyticsControlsEvent("color-by-genotype");
this.props.dispatch(changeColorBy(genotype));
this.dispatchColorByGenotype(genotype);
}
}
} else {
analyticsControlsEvent(`color-by-${colorBySelected}`);
this.props.dispatch(changeColorBy(colorBySelected));
this.dispatchColorBy(colorBySelected);
}
}

dispatchColorBy(colorBy, name = colorBy) {
analyticsControlsEvent(`color-by-${name}`);
this.props.dispatch(changeColorBy(colorBy));
}

dispatchColorByGenotype = debounce((genotype) => {
this.dispatchColorBy(genotype, "genotype");
}, 400);

getGtGeneOptions() {
let options = [];
if (this.props.geneMap) {
Expand Down

0 comments on commit 1b46f72

Please sign in to comment.