Optimise Widget rendering

Names and lists of values should always remain the same, only update on value/readonly changes.
This commit is contained in:
Ingvar Stepanyan
2021-07-23 17:01:40 +00:00
parent fa2084a9d7
commit 585001bd4e

View File

@@ -2,6 +2,17 @@ import { h, Component, createRef } from 'preact';
/** @typedef {import('../libapi.mjs').Config} Config */ /** @typedef {import('../libapi.mjs').Config} Config */
/**
* @param {Config} config
*/
function getValueForComparison(config) {
if (config.type === 'window' || config.type === 'section') {
// compare instances themselves
return config;
}
return config.value;
}
/** /**
* *
* @extends Component<{ config: Config, setValue: (name: string, value: any) => Promise<void> }> * @extends Component<{ config: Config, setValue: (name: string, value: any) => Promise<void> }>
@@ -13,7 +24,14 @@ export class Widget extends Component {
/** @type {Widget['props']} */ nextProps, /** @type {Widget['props']} */ nextProps,
/** @type {Widget['state']} */ nextState /** @type {Widget['state']} */ nextState
) { ) {
return !(this.state.inProgress && nextState.inProgress); if (this.state.inProgress && nextState.inProgress) {
return false;
}
return (
getValueForComparison(this.props.config) !==
getValueForComparison(nextProps.config) ||
this.props.config.readonly !== nextProps.config.readonly
);
} }
getValueProp(out = false) { getValueProp(out = false) {