mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
fix depends validation & unsubscribe update events for unmounted items
This commit is contained in:
parent
4f19250d07
commit
aa84b5d006
@ -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") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user