Fix components not updating when the enable condition changed

This commit is contained in:
uwap 2018-10-20 11:04:44 +02:00
parent a0cb05b294
commit 42e312c701

View file

@ -50,16 +50,20 @@ export default class UiItem<I:Object>
* any function type or if it is a TopicDependentOption or a * any function type or if it is a TopicDependentOption or a
* StateDependentOption. This should be fixed. * StateDependentOption. This should be fixed.
*/ */
isEnabled() { rawIsEnabled(props: UiItemProps<I>) {
if (Object.keys(this.props.item).includes("enableCondition") && if (Object.keys(props.item).includes("enableCondition") &&
typeof this.props.item.enableCondition == "function") { typeof props.item.enableCondition == "function") {
const enableCondition = this.props.item.enableCondition; const enableCondition = props.item.enableCondition;
const state = this.props.state; const state = props.state;
return enableCondition(state); return enableCondition(state);
} else { } else {
return true; return true;
} }
} }
isEnabled() {
return this.rawIsEnabled(this.props);
}
} }
export class UiControl<I: UIControl> extends UiItem<I> { export class UiControl<I: UIControl> extends UiItem<I> {
@ -86,7 +90,8 @@ export class UiControl<I: UIControl> extends UiItem<I> {
shouldComponentUpdate(nextProps: UiItemProps<I>) { // TODO: Fix Flow shouldComponentUpdate(nextProps: UiItemProps<I>) { // TODO: Fix Flow
return nextProps.item.topic !== this.props.item.topic return nextProps.item.topic !== this.props.item.topic
|| nextProps.state[nextProps.item.topic] !== || nextProps.state[nextProps.item.topic] !==
this.props.state[this.props.item.topic]; this.props.state[this.props.item.topic]
|| this.isEnabled() !== this.rawIsEnabled(nextProps);
} }
getValue() { getValue() {