generated from Seekra/repository-template
feat(settings): make setting value function synchronous
Added a store to cache the settings configuration. The getSetting function from useSettings is now synchronous and uses this cache. The settings cache is set when loading the settings initially (asnychronously).
This commit is contained in:
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { useSettingsConfigCacheStore } from '../stores/settingsConfigCacheStore';
|
||||
import { validateSettingsConfig } from './settingsValidator.js';
|
||||
|
||||
/**
|
||||
@@ -21,10 +22,12 @@ import { validateSettingsConfig } from './settingsValidator.js';
|
||||
* @returns {Promise<import('../types/settingsConfig').SettingsConfig>}
|
||||
*/
|
||||
export async function loadSettingsConfig() {
|
||||
const settingsConfigCache = useSettingsConfigCacheStore();
|
||||
let raw;
|
||||
|
||||
try {
|
||||
raw = (await import('../settings.json')).default;
|
||||
settingsConfigCache.set(raw);
|
||||
} catch (e) {
|
||||
throw new Error(`[settings] Failed to load settings.json: ${e.message}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user