SettingGroupManager.mjs (1051B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /** @import {SettingGroupConfig} from "chrome://browser/content/preferences/widgets/setting-group.mjs" */ 6 7 export const SettingGroupManager = { 8 /** @type {Map<string, SettingGroupConfig>} */ 9 _data: new Map(), 10 11 /** 12 * @param {string} id 13 */ 14 get(id) { 15 if (!this._data.has(id)) { 16 throw new Error(`Setting group "${id}" not found`); 17 } 18 return this._data.get(id); 19 }, 20 21 /** 22 * @param {string} id 23 * @param {SettingGroupConfig} config 24 */ 25 registerGroup(id, config) { 26 if (this._data.has(id)) { 27 throw new Error(`Setting group "${id}" already registered`); 28 } 29 this._data.set(id, config); 30 }, 31 32 /** 33 * @param {Record<string, SettingGroupConfig>} groupConfigs 34 */ 35 registerGroups(groupConfigs) { 36 for (let id in groupConfigs) { 37 this.registerGroup(id, groupConfigs[id]); 38 } 39 }, 40 };