Greatly improve the performance
This commit is contained in:
parent
01d330a490
commit
bc99051aa0
1 changed files with 36 additions and 29 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import * as React from "react";
|
||||||
import map from "lodash/map";
|
import map from "lodash/map";
|
||||||
import mapValues from "lodash/mapValues";
|
import mapValues from "lodash/mapValues";
|
||||||
import filter from "lodash/filter";
|
import filter from "lodash/filter";
|
||||||
|
|
@ -39,6 +39,8 @@ export type AppState = {
|
||||||
};
|
};
|
||||||
|
|
||||||
class App extends React.PureComponent<AppProps & Classes, AppState> {
|
class App extends React.PureComponent<AppProps & Classes, AppState> {
|
||||||
|
controlMap: React.Node
|
||||||
|
|
||||||
constructor(props: AppProps & Classes) {
|
constructor(props: AppProps & Classes) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|
@ -57,6 +59,12 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
|
||||||
mqttConnected: false,
|
mqttConnected: false,
|
||||||
error: null
|
error: null
|
||||||
};
|
};
|
||||||
|
this.controlMap =
|
||||||
|
<ControlMap width={1000} height={700} zoom={0}
|
||||||
|
layers={this.props.config.layers}
|
||||||
|
controls={this.props.config.controls}
|
||||||
|
onChangeControl={this.changeControl}
|
||||||
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
get topics(): Topics {
|
get topics(): Topics {
|
||||||
|
|
@ -72,10 +80,10 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get theme() {
|
static theme(config: Config) {
|
||||||
return createMuiTheme({
|
return createMuiTheme({
|
||||||
palette: {
|
palette: {
|
||||||
primary: Colors[this.props.config.space.color]
|
primary: Colors[config.space.color]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -104,17 +112,17 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMqttStateDebounced = throttle(this.setState, 32);
|
setMqttStateDebounced = throttle(this.setState, 16);
|
||||||
|
|
||||||
changeControl(control: ?Control = null) {
|
changeControl = (control: ?Control = null) => {
|
||||||
this.setState({selectedControl: control, drawerOpened: control != null});
|
this.setState({selectedControl: control, drawerOpened: control != null});
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDrawer() {
|
closeDrawer = () => {
|
||||||
this.setState({drawerOpened: false});
|
this.setState({drawerOpened: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
changeState(topic: string, value: string) {
|
changeState = (topic: string, value: string) => {
|
||||||
try {
|
try {
|
||||||
if (this.topics[topic].command == null) {
|
if (this.topics[topic].command == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -133,28 +141,20 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
|
||||||
return (
|
return (
|
||||||
<MqttContext.Provider value={{
|
<MqttContext.Provider value={{
|
||||||
state: this.state.mqttState,
|
state: this.state.mqttState,
|
||||||
changeState: this.changeState.bind(this)
|
changeState: this.changeState
|
||||||
}}>
|
}}>
|
||||||
<MuiThemeProvider theme={this.theme}>
|
<TopBar title={`${this.props.config.space.name} Map`}
|
||||||
<React.Fragment>
|
connected={this.state.mqttConnected} />
|
||||||
<TopBar title={`${this.props.config.space.name} Map`}
|
<SideBar open={this.state.drawerOpened}
|
||||||
connected={this.state.mqttConnected} />
|
control={this.state.selectedControl}
|
||||||
<SideBar open={this.state.drawerOpened}
|
onCloseRequest={this.closeDrawer}
|
||||||
control={this.state.selectedControl}
|
icon={this.state.selectedControl == null ? null :
|
||||||
onCloseRequest={this.closeDrawer.bind(this)}
|
this.state.selectedControl.icon(this.state.mqttState)}
|
||||||
icon={this.state.selectedControl == null ? null :
|
>
|
||||||
this.state.selectedControl.icon(this.state.mqttState)}
|
{this.state.selectedControl == null
|
||||||
>
|
|| <UiItemList controls={this.state.selectedControl.ui} />}
|
||||||
{this.state.selectedControl == null
|
</SideBar>
|
||||||
|| <UiItemList controls={this.state.selectedControl.ui} />}
|
{this.controlMap}
|
||||||
</SideBar>
|
|
||||||
</React.Fragment>
|
|
||||||
</MuiThemeProvider>
|
|
||||||
<ControlMap width={1000} height={700} zoom={0}
|
|
||||||
layers={this.props.config.layers}
|
|
||||||
controls={this.props.config.controls}
|
|
||||||
onChangeControl={this.changeControl.bind(this)}
|
|
||||||
/>
|
|
||||||
<Snackbar
|
<Snackbar
|
||||||
anchorOrigin={{
|
anchorOrigin={{
|
||||||
vertical: "bottom",
|
vertical: "bottom",
|
||||||
|
|
@ -184,4 +184,11 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withStyles(App.styles)(App);
|
export default (props: AppProps) => {
|
||||||
|
const StyledApp = withStyles(App.styles)(App);
|
||||||
|
return (
|
||||||
|
<MuiThemeProvider theme={App.theme(props.config)}>
|
||||||
|
<StyledApp {...props} />
|
||||||
|
</MuiThemeProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue