From f03b7ce306575e60c60e7d98780c200d288a6dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=91?= <1395348685z@gmail.com> Date: Mon, 31 May 2021 20:12:19 +0800 Subject: [PATCH] Fix overwritten of non-object in CONFIG (#279) --- source/js/config.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/source/js/config.js b/source/js/config.js index 8c96b6c..4d6d7ad 100644 --- a/source/js/config.js +++ b/source/js/config.js @@ -36,20 +36,31 @@ if (!window.NexT) window.NexT = {}; existing = variableConfig[name]; } - let override = overrideConfig[name]; - if (override === undefined && typeof existing === 'object') { - override = {}; - overrideConfig[name] = override; + // For unset override and mixable existing + if (!(name in overrideConfig) && typeof existing === 'object') { + // Get ready to mix. + overrideConfig[name] = {}; } - if (typeof override === 'object') { - return new Proxy({...existing, ...override}, { - set(target, prop, value) { - override[prop] = value; - return true; - } - }); + if (name in overrideConfig) { + const override = overrideConfig[name]; + + // When mixable + if (typeof override === 'object' && typeof existing === 'object') { + // Mix, proxy changes to the override. + return new Proxy({...existing, ...override}, { + set(target, prop, value) { + target[prop] = value; + override[prop] = value; + return true; + } + }); + } + + return override; } + + // Only when not mixable and override hasn't been set. return existing; } });