From 42e312c7014414557a970210cbe287055edd3897 Mon Sep 17 00:00:00 2001 From: uwap Date: Sat, 20 Oct 2018 11:04:44 +0200 Subject: [PATCH] Fix components not updating when the enable condition changed --- src/components/UiItemList/UiItem.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/UiItemList/UiItem.js b/src/components/UiItemList/UiItem.js index e688c14..70cc53e 100644 --- a/src/components/UiItemList/UiItem.js +++ b/src/components/UiItemList/UiItem.js @@ -50,16 +50,20 @@ export default class UiItem * any function type or if it is a TopicDependentOption or a * StateDependentOption. This should be fixed. */ - isEnabled() { - if (Object.keys(this.props.item).includes("enableCondition") && - typeof this.props.item.enableCondition == "function") { - const enableCondition = this.props.item.enableCondition; - const state = this.props.state; + rawIsEnabled(props: UiItemProps) { + if (Object.keys(props.item).includes("enableCondition") && + typeof props.item.enableCondition == "function") { + const enableCondition = props.item.enableCondition; + const state = props.state; return enableCondition(state); } else { return true; } } + + isEnabled() { + return this.rawIsEnabled(this.props); + } } export class UiControl extends UiItem { @@ -86,7 +90,8 @@ export class UiControl extends UiItem { shouldComponentUpdate(nextProps: UiItemProps) { // TODO: Fix Flow return nextProps.item.topic !== this.props.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() {