Fix performance issue
When the root node was collapsed, it also was selected due to the click event. The sidebar was updated every time a new message was receivend, effectivly inhibiting the "render the tree if you got nothing else to do" optimization to render anything at all. Fixes #7
This commit is contained in:
@@ -9,6 +9,8 @@ import Paper from '@material-ui/core/Paper'
|
||||
import Popper from '@material-ui/core/Popper'
|
||||
import ValueRenderer from './ValueRenderer'
|
||||
|
||||
const throttle = require('lodash.throttle')
|
||||
|
||||
interface Props {
|
||||
node?: q.TreeNode
|
||||
theme: Theme
|
||||
@@ -26,9 +28,9 @@ class MessageHistory extends React.Component<Props, State> {
|
||||
this.state = { }
|
||||
}
|
||||
|
||||
private updateNode = () => {
|
||||
private updateNode = throttle(() => {
|
||||
this.setState(this.state)
|
||||
}
|
||||
}, 300)
|
||||
|
||||
public componentWillReceiveProps(nextProps: Props) {
|
||||
this.props.node && this.props.node.onMessage.unsubscribe(this.updateNode)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as React from 'react'
|
||||
import * as q from '../../../../backend/src/Model'
|
||||
|
||||
import { Typography } from '@material-ui/core'
|
||||
|
||||
interface Props {
|
||||
|
||||
@@ -22,6 +22,8 @@ import Topic from './Topic'
|
||||
import ValueRenderer from './ValueRenderer'
|
||||
import { connect } from 'react-redux'
|
||||
|
||||
const throttle = require('lodash.throttle')
|
||||
|
||||
interface Props {
|
||||
node?: q.TreeNode,
|
||||
classes: any,
|
||||
@@ -36,9 +38,9 @@ interface State {
|
||||
|
||||
class Sidebar extends React.Component<Props, State> {
|
||||
private valueRef: any = React.createRef<HTMLDivElement>()
|
||||
private updateNode = () => {
|
||||
private updateNode = throttle(() => {
|
||||
this.setState(this.state)
|
||||
}
|
||||
}, 300)
|
||||
|
||||
constructor(props: any) {
|
||||
super(props)
|
||||
|
||||
Reference in New Issue
Block a user