From 4b84c1427aca2c78a74633a3bef292fff91afcc1 Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Thu, 28 Nov 2024 19:27:10 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Regenerate=20the=20`alchemy.s?= =?UTF-8?q?ettings`=20object=20when=20updating=20any=20setting's=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + lib/app/model/system_setting_model.js | 11 +++++++++-- lib/core/alchemy.js | 13 ++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd7318..254791d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Fix `_modelInstance` cache when keys are not strings * Fix certain settings not being applied if they're created after generating the main system setting object * Fix settings proxy objects +* Regenerate the `alchemy.settings` object when updating any setting's value ## 1.4.0-alpha.7 (2024-10-10) diff --git a/lib/app/model/system_setting_model.js b/lib/app/model/system_setting_model.js index 7b1cb1c..a413a79 100644 --- a/lib/app/model/system_setting_model.js +++ b/lib/app/model/system_setting_model.js @@ -147,9 +147,16 @@ SystemSetting.setDocumentMethod(function applySetting(do_actions = true) { alchemy.system_settings.forceValueInstanceAtPath(this.setting_id, existing_value); } + let result; + if (do_actions) { - return existing_value.setValue(this.configuration.value); + result = existing_value.setValue(this.configuration.value); } else { - return existing_value.setValueSilently(this.configuration.value); + result = existing_value.setValueSilently(this.configuration.value); } + + // And now force the settings to update! + alchemy.refreshSettingsObject(); + + return result; }); \ No newline at end of file diff --git a/lib/core/alchemy.js b/lib/core/alchemy.js index 2882706..826b250 100644 --- a/lib/core/alchemy.js +++ b/lib/core/alchemy.js @@ -580,10 +580,21 @@ Alchemy.setMethod(function setSetting(path, value) { this.system_settings.setPathSilently(path, value); if (this.started) { - this.settings = this.system_settings.toObject(); + this.refreshSettingsObject(); } }); +/** + * Refresh the settings object + * + * @author Jelle De Loecker + * @since 1.4.0 + * @version 1.4.0 + */ +Alchemy.setMethod(function refreshSettingsObject() { + this.settings = this.system_settings.toObject(); +}); + /** * Get a setting value *