Skip to content

Commit

Permalink
[#172] Moved handleResize to OrderBookSnapshot attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
panoreak committed Feb 5, 2020
1 parent 0fa0894 commit 9b9baa4
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions app/src/components/OrderBookSnapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ interface State {
}

class OrderBookSnapshot extends Component<WithStyles, State> {
/**
* @desc Handles window resizing and requests a new number of data points appropriate for the new window width
*/
handleResize = debounce(() => {
const { selectedDateNano } = this.state;
if (selectedDateNano.neq(0)) {
const startTime = selectedDateNano.plus(NANOSECONDS_IN_NINE_AND_A_HALF_HOURS);
const endTime = selectedDateNano.plus(NANOSECONDS_IN_SIXTEEN_HOURS);
this.updateGraphData(startTime, endTime);
}
}, 100);

constructor(props) {
super(props);

Expand Down Expand Up @@ -87,7 +99,7 @@ class OrderBookSnapshot extends Component<WithStyles, State> {
this.setState({ loadingInstruments: false });
});

window.addEventListener('resize', debounce(this.handleResize, 100));
window.addEventListener('resize', this.handleResize);
}

componentDidUpdate(prevProps, prevState, snapshot) {
Expand All @@ -98,22 +110,9 @@ class OrderBookSnapshot extends Component<WithStyles, State> {
}

componentWillUnmount() {
window.removeEventListener('resize', debounce(this.handleResize, 100));
window.removeEventListener('resize', this.handleResize);
}


/**
* @desc Handles window resizing and requests a new number of data points appropriate for the new window width
*/
handleResize = () => {
const { selectedDateNano } = this.state;
if (selectedDateNano.neq(0)) {
const startTime = selectedDateNano.plus(NANOSECONDS_IN_NINE_AND_A_HALF_HOURS);
const endTime = selectedDateNano.plus(NANOSECONDS_IN_SIXTEEN_HOURS);
this.updateGraphData(startTime, endTime);
}
};

/**
* @desc Handles the change in instrument
* @param event menu item that triggered change
Expand Down

0 comments on commit 9b9baa4

Please sign in to comment.