From bc99051aa08e5d16195021d66a1d1ccadd0fd219 Mon Sep 17 00:00:00 2001 From: uwap Date: Wed, 1 Aug 2018 01:56:15 +0200 Subject: [PATCH] Greatly improve the performance --- src/components/App.js | 65 ++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/src/components/App.js b/src/components/App.js index b0fa510..616d32c 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,5 +1,5 @@ // @flow -import React from "react"; +import * as React from "react"; import map from "lodash/map"; import mapValues from "lodash/mapValues"; import filter from "lodash/filter"; @@ -39,6 +39,8 @@ export type AppState = { }; class App extends React.PureComponent { + controlMap: React.Node + constructor(props: AppProps & Classes) { super(props); this.state = { @@ -57,6 +59,12 @@ class App extends React.PureComponent { mqttConnected: false, error: null }; + this.controlMap = + ; } get topics(): Topics { @@ -72,10 +80,10 @@ class App extends React.PureComponent { }; } - get theme() { + static theme(config: Config) { return createMuiTheme({ palette: { - primary: Colors[this.props.config.space.color] + primary: Colors[config.space.color] } }); } @@ -104,17 +112,17 @@ class App extends React.PureComponent { } } - 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}); } - closeDrawer() { + closeDrawer = () => { this.setState({drawerOpened: false}); } - changeState(topic: string, value: string) { + changeState = (topic: string, value: string) => { try { if (this.topics[topic].command == null) { return; @@ -133,28 +141,20 @@ class App extends React.PureComponent { return ( - - - - - {this.state.selectedControl == null - || } - - - - + + + {this.state.selectedControl == null + || } + + {this.controlMap} { } } -export default withStyles(App.styles)(App); +export default (props: AppProps) => { + const StyledApp = withStyles(App.styles)(App); + return ( + + + + ); +};