Rename .js/.jsx to .ts/.tsx
This commit is contained in:
parent
257162e5b6
commit
c60d0e7392
151 changed files with 0 additions and 0 deletions
32
src/shared/settings/storage.ts
Normal file
32
src/shared/settings/storage.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import DefaultSettings from './default';
|
||||
import * as settingsValues from './values';
|
||||
|
||||
const loadRaw = async() => {
|
||||
let { settings } = await browser.storage.local.get('settings');
|
||||
if (!settings) {
|
||||
return DefaultSettings;
|
||||
}
|
||||
return { ...DefaultSettings, ...settings };
|
||||
};
|
||||
|
||||
const loadValue = async() => {
|
||||
let settings = await loadRaw();
|
||||
let value = JSON.parse(DefaultSettings.json);
|
||||
if (settings.source === 'json') {
|
||||
value = settingsValues.valueFromJson(settings.json);
|
||||
} else if (settings.source === 'form') {
|
||||
value = settingsValues.valueFromForm(settings.form);
|
||||
}
|
||||
if (!value.properties) {
|
||||
value.properties = {};
|
||||
}
|
||||
return { ...settingsValues.valueFromJson(DefaultSettings.json), ...value };
|
||||
};
|
||||
|
||||
const save = (settings) => {
|
||||
return browser.storage.local.set({
|
||||
settings,
|
||||
});
|
||||
};
|
||||
|
||||
export { loadRaw, loadValue, save };
|
Reference in a new issue