From aa84b5d0061bcb982a36727f252fd98cebadca06 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Tue, 31 May 2022 00:51:04 +0200 Subject: [PATCH] fix depends validation & unsubscribe update events for unmounted items --- packages/app/src/components/Settings/index.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/app/src/components/Settings/index.jsx b/packages/app/src/components/Settings/index.jsx index 80e19cdc..9edb6142 100644 --- a/packages/app/src/components/Settings/index.jsx +++ b/packages/app/src/components/Settings/index.jsx @@ -100,6 +100,15 @@ const SettingItem = (props) => { } } + const onUnmount = () => { + // unsubscribe eventBus events + if (typeof item.dependsOn === "object") { + for (let key in item.dependsOn) { + window.app.eventBus.off(`setting.update.${key}`, onUpdateItem) + } + } + } + const checkDependsValidation = () => { return !Boolean(Object.keys(item.dependsOn).every((key) => { const storagedValue = window.app.settings.get(key) @@ -133,7 +142,7 @@ const SettingItem = (props) => { }) // by default check depends validation - item.props.disabled = checkDependsValidation() + setDisabled(checkDependsValidation()) } if (typeof item.listenUpdateValue === "string") { @@ -152,6 +161,8 @@ const SettingItem = (props) => { React.useEffect(() => { settingInitialization() + + return onUnmount }, []) if (typeof SettingComponent === "string") {