Fix state mixup
This commit is contained in:
@@ -29,7 +29,7 @@ import Publish from './Publish/Publish'
|
|||||||
import Topic from './Topic'
|
import Topic from './Topic'
|
||||||
import ValueRenderer from './ValueRenderer'
|
import ValueRenderer from './ValueRenderer'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux'
|
||||||
|
|
||||||
const throttle = require('lodash.throttle')
|
const throttle = require('lodash.throttle')
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Tree extends React.Component<Props, TreeState> {
|
|||||||
average.push(Date.now(), ms)
|
average.push(Date.now(), ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
public throttledStateUpdate(state: any) {
|
public throttledTreeUpdate() {
|
||||||
if (this.updateTimer) {
|
if (this.updateTimer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ class Tree extends React.Component<Props, TreeState> {
|
|||||||
this.lastUpdate = performance.now()
|
this.lastUpdate = performance.now()
|
||||||
this.updateTimer && clearTimeout(this.updateTimer)
|
this.updateTimer && clearTimeout(this.updateTimer)
|
||||||
this.updateTimer = undefined
|
this.updateTimer = undefined
|
||||||
this.setState(state)
|
this.setState(this.state)
|
||||||
}, { timeout: 500 })
|
}, { timeout: 500 })
|
||||||
}, Math.max(0, timeUntilNextUpdate))
|
}, Math.max(0, timeUntilNextUpdate))
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,7 @@ class Tree extends React.Component<Props, TreeState> {
|
|||||||
if (this.props.connectionId) {
|
if (this.props.connectionId) {
|
||||||
this.setState({ tree: new q.Tree() })
|
this.setState({ tree: new q.Tree() })
|
||||||
rendererEvents.unsubscribeAll(makeConnectionMessageEvent(this.props.connectionId))
|
rendererEvents.unsubscribeAll(makeConnectionMessageEvent(this.props.connectionId))
|
||||||
|
this.updateTimer && clearTimeout(this.updateTimer)
|
||||||
}
|
}
|
||||||
if (nextProps.connectionId) {
|
if (nextProps.connectionId) {
|
||||||
rendererEvents.subscribe(makeConnectionMessageEvent(nextProps.connectionId), this.handleNewData)
|
rendererEvents.subscribe(makeConnectionMessageEvent(nextProps.connectionId), this.handleNewData)
|
||||||
@@ -95,7 +96,7 @@ class Tree extends React.Component<Props, TreeState> {
|
|||||||
node.mqttMessage = msg
|
node.mqttMessage = msg
|
||||||
this.state.tree.updateWithNode(node.firstNode())
|
this.state.tree.updateWithNode(node.firstNode())
|
||||||
|
|
||||||
this.throttledStateUpdate({ msg, tree: this.state.tree })
|
this.throttledTreeUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
|||||||
Reference in New Issue
Block a user