aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings/settings-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-30 21:53:36 -0400
committerGitHub <noreply@github.com>2020-05-30 21:53:36 -0400
commitdb209c9116135528bbe0bffcd9763e9914da2441 (patch)
treea57f4bb22a67168f78521e43aff859cea3609369 /ext/bg/js/settings/settings-controller.js
parentce7f9dd09a85f182a9ea98c3366bed6c2ecbb1b4 (diff)
Generic settings controller merge (#584)
* Update how optionsContext is assigned to targets * Add getSettings and modifySettings * Merge DOMSettingsBinder into GenericSettingController * Remove old DOMSettingsBinder
Diffstat (limited to 'ext/bg/js/settings/settings-controller.js')
-rw-r--r--ext/bg/js/settings/settings-controller.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index 4c902dff..87dea408 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -73,12 +73,20 @@ class SettingsController extends EventDispatcher {
this._setProfileIndex(profileIndex);
}
+ async getSettings(targets) {
+ return await this._getSettings(targets, {});
+ }
+
async getGlobalSettings(targets) {
return await this._getSettings(targets, {scope: 'global'});
}
async getProfileSettings(targets) {
- return await this._getSettings(targets, {scope: 'profile', optionsContext: this.getOptionsContext()});
+ return await this._getSettings(targets, {scope: 'profile'});
+ }
+
+ async modifySettings(targets) {
+ return await this._modifySettings(targets, {});
}
async modifyGlobalSettings(targets) {
@@ -86,7 +94,7 @@ class SettingsController extends EventDispatcher {
}
async modifyProfileSettings(targets) {
- return await this._modifySettings(targets, {scope: 'profile', optionsContext: this.getOptionsContext()});
+ return await this._modifySettings(targets, {scope: 'profile'});
}
async setGlobalSetting(path, value) {
@@ -120,13 +128,23 @@ class SettingsController extends EventDispatcher {
this.trigger('optionsChanged', {options, optionsContext});
}
+ _setupTargets(targets, extraFields) {
+ return targets.map((target) => {
+ target = Object.assign({}, extraFields, target);
+ if (target.scope === 'profile') {
+ target.optionsContext = this.getOptionsContext();
+ }
+ return target;
+ });
+ }
+
async _getSettings(targets, extraFields) {
- targets = targets.map((target) => Object.assign({}, target, extraFields));
+ targets = this._setupTargets(targets, extraFields);
return await api.getSettings(targets);
}
async _modifySettings(targets, extraFields) {
- targets = targets.map((target) => Object.assign({}, target, extraFields));
+ targets = this._setupTargets(targets, extraFields);
return await api.modifySettings(targets, this._source);
}
}