Skip to content

Commit

Permalink
šŸ› Fix certain settings not being applied if they're created after genā€¦
Browse files Browse the repository at this point in the history
ā€¦erating the main system setting object
  • Loading branch information
skerit committed Nov 28, 2024
1 parent 59e82a4 commit 785279c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.4.0-alpha.8 (WIP)

* 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

## 1.4.0-alpha.7 (2024-10-10)

Expand Down
1 change: 1 addition & 0 deletions lib/app/model/system_setting_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ SystemSetting.setDocumentMethod(function applySetting(do_actions = true) {

if (!existing_value) {
existing_value = setting.generateValue();
alchemy.system_settings.forceValueInstanceAtPath(this.setting_id, existing_value);
}

if (do_actions) {
Expand Down
59 changes: 59 additions & 0 deletions lib/core/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ const Group = Function.inherits('Alchemy.Setting.Base', function Group(name, con

// All the children
this.children = new Map();

// Weak references to existing values
this.weak_values = new Blast.Classes.WeakValueSet();
});

/**
Expand Down Expand Up @@ -583,6 +586,14 @@ Group.setMethod(function createGroup(name) {
let group = new Group(name, this);
this.children.set(name, group);

if (this.weak_values.size) {
let group_value = group.generateValue();

for (let existing of this.weak_values) {
this.setDefaultValue(existing, {[name]: group_value});
}
}

return group;
});

Expand Down Expand Up @@ -633,6 +644,8 @@ Group.setMethod(function generateValue() {

this.setDefaultValue(result, object);

this.weak_values.add(result);

return result;
});

Expand Down Expand Up @@ -1344,6 +1357,38 @@ GroupValue.setMethod(function _setPath(silent, path, raw_value) {
return this.getPath(path);
});

/**
* Force a value at the given path
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @param {string|Array} path
* @param {Value}
*/
GroupValue.setMethod(function forceValueInstanceAtPath(path, value) {

if (typeof path == 'string') {
path = path.split('.');
}

if (this.definition.group == null && path[0] == this.definition.name) {
path.shift();
}

let last = path.pop();

let current = this;

while (path.length && current) {
let next = path.shift();
current = current.get(next);
}

current[VALUE][last] = value;
});

/**
* Convert to a datasource array
*
Expand Down Expand Up @@ -1584,6 +1629,20 @@ Value.setMethod(function getPath(path) {
return current;
});

/**
* Force a value at the given path
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @param {string|Array} path
* @param {Value}
*/
Value.setMethod(function forceValueInstanceAtPath(path, value) {
throw new Error('Unable to perform on a simple Value instance');
});

if (Blast.isBrowser) {
return;
}
Expand Down

0 comments on commit 785279c

Please sign in to comment.