Answer the question
In order to leave comments, you need to log in
What is the best way to organize the storage of settings and parameters that are common to several components?
I write in TypeScript.
What is the best way to store settings that are common to several components?
To be more precise, there are 5 components so far, then, perhaps, there will be more of them.
Most settings are read-only, but some are writable.
At the moment, the settings are placed in a separate component-class Settings, the settings are grouped by meaning into objects and are private properties of this class, accessed through the getSetting(settingName) method. As a result, such properties are obtained in the region of 10-15.
Each of the settings can be used in several components.
In the component where these settings (Settings class) are used, they are passed as a constructor argument as a dependency (ioc) and assigned to properties of this class that are similar in name to the settings. Well, then we turn to the settings through this.
constructor (settings) {
this._settingNameA = settings.getSetting('settingNameA');
this._settingNameB = settings.getSetting('settingNameB');
}
let value = this._settings.getSetting('settingNameC').blablabla + this._settings.getSetting('settingNameD');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question