Fix state mixup

This commit is contained in:
Thomas Nordquist
2019-01-20 18:48:18 +01:00
parent 82ef5bc4e7
commit 1719876734
2 changed files with 5 additions and 4 deletions

View File

@@ -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')

View File

@@ -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() {