Fix Settings errors when retrieving a null value; add PlainSettings
This commit is contained in:
parent
ea0ded0f11
commit
bf49acd535
2 changed files with 10 additions and 4 deletions
|
@ -5,10 +5,10 @@ export * as Updater from "./utils/updater";
|
||||||
export * as QuickCss from "./utils/quickCss";
|
export * as QuickCss from "./utils/quickCss";
|
||||||
|
|
||||||
import { popNotice, showNotice } from "./api/Notices";
|
import { popNotice, showNotice } from "./api/Notices";
|
||||||
import { Settings } from "./api/settings";
|
import { Settings, PlainSettings } from "./api/settings";
|
||||||
import { startAllPlugins } from "./plugins";
|
import { startAllPlugins } from "./plugins";
|
||||||
|
|
||||||
export { Settings };
|
export { Settings, PlainSettings };
|
||||||
|
|
||||||
import "./webpack/patchWebpack";
|
import "./webpack/patchWebpack";
|
||||||
import "./utils/quickCss";
|
import "./utils/quickCss";
|
||||||
|
|
|
@ -46,7 +46,7 @@ function makeProxy(settings: Settings, root = settings, path = ""): Settings {
|
||||||
return new Proxy(settings, {
|
return new Proxy(settings, {
|
||||||
get(target, p: string) {
|
get(target, p: string) {
|
||||||
const v = target[p];
|
const v = target[p];
|
||||||
if (typeof v === "object" && !Array.isArray(v))
|
if (typeof v === "object" && !Array.isArray(v) && v !== null)
|
||||||
return makeProxy(v, root, `${path}${path && "."}${p}`);
|
return makeProxy(v, root, `${path}${path && "."}${p}`);
|
||||||
return v;
|
return v;
|
||||||
},
|
},
|
||||||
|
@ -66,12 +66,18 @@ function makeProxy(settings: Settings, root = settings, path = ""): Settings {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as {@link Settings} but unproxied. You should treat this as readonly,
|
||||||
|
* as modifying properties on this will not save to disk or call settings
|
||||||
|
* listeners.
|
||||||
|
*/
|
||||||
|
export const PlainSettings = settings;
|
||||||
/**
|
/**
|
||||||
* A smart settings object. Altering props automagically saves
|
* A smart settings object. Altering props automagically saves
|
||||||
* the updated settings to disk.
|
* the updated settings to disk.
|
||||||
|
* This recursively proxies objects. If you need the object non proxied, use {@link PlainSettings}
|
||||||
*/
|
*/
|
||||||
export const Settings = makeProxy(settings);
|
export const Settings = makeProxy(settings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings hook for React components. Returns a smart settings
|
* Settings hook for React components. Returns a smart settings
|
||||||
* object that automagically triggers a rerender if any properties
|
* object that automagically triggers a rerender if any properties
|
||||||
|
|
Loading…
Reference in a new issue