Small performance optimization

This commit is contained in:
uwap 2018-08-12 01:27:14 +02:00
parent c7202a9141
commit 21e246c98a
2 changed files with 8 additions and 2 deletions

View file

@ -32,7 +32,7 @@ type UiItemProps<I> = {
// eslint-disable-next-line flowtype/no-weak-types // eslint-disable-next-line flowtype/no-weak-types
export default class UiItem<I:Object> export default class UiItem<I:Object>
extends React.PureComponent<UiItemProps<I>> { extends React.Component<UiItemProps<I>> {
constructor(props: UiItemProps<I>) { constructor(props: UiItemProps<I>) {
super(props); super(props);
} }
@ -82,6 +82,12 @@ export class UiControl<I: UIControl> extends UiItem<I> {
trailing: true trailing: true
}); });
// $FlowFixMe
shouldComponentUpdate(nextProps: UiItemProps<I>) { // TODO: Fix Flow
return nextProps.state[nextProps.item.topic] !==
this.props.state[this.props.item.topic];
}
getValue() { getValue() {
const control = this.props.item; const control = this.props.item;
const topic: string = control.topic || ""; const topic: string = control.topic || "";

View file

@ -62,7 +62,7 @@ export default class UiItemList extends React.PureComponent<UiItemListProps> {
renderControl(control: ControlUI, key: string, mqtt: MqttContextValue) { renderControl(control: ControlUI, key: string, mqtt: MqttContextValue) {
const props = { const props = {
state: mqtt.state, state: Object.assign({}, mqtt.state),
onChangeState: mqtt.changeState, onChangeState: mqtt.changeState,
key: `${key}-licontrol` key: `${key}-licontrol`
}; };