Properly parse empty setting value for booleans and integers
parent
7f6af3c304
commit
3e42c7027f
|
@ -80,19 +80,31 @@ function resolveKey<ValueType extends RegistryValueType, DefaultType>(
|
|||
) : ValueType | DefaultType {
|
||||
let value = resolver(key.key);
|
||||
|
||||
if(typeof value === "string") {
|
||||
return decodeValueFromString(value, key.valueType);
|
||||
const keys = [key.key];
|
||||
if(Array.isArray(key.fallbackKeys)) {
|
||||
keys.push(...key.fallbackKeys);
|
||||
}
|
||||
|
||||
/* trying fallback values */
|
||||
for(const fallback of key.fallbackKeys || []) {
|
||||
value = resolver(fallback);
|
||||
for(const resolveKey of keys) {
|
||||
value = resolver(resolveKey);
|
||||
if(typeof value !== "string") {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (key.valueType) {
|
||||
case "number":
|
||||
case "boolean":
|
||||
if(value.length === 0) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(key.fallbackImports) {
|
||||
const fallbackValueImporter = key.fallbackImports[fallback];
|
||||
const fallbackValueImporter = key.fallbackImports[resolveKey];
|
||||
if(fallbackValueImporter) {
|
||||
return fallbackValueImporter(value);
|
||||
}
|
||||
|
|
|
@ -34,10 +34,11 @@ export function joinClassList(...classes: any[]) : string {
|
|||
return classes.filter(value => typeof value === "string" && value.length > 0).join(" ");
|
||||
}
|
||||
|
||||
export function useGlobalSetting<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV) : V | DV;
|
||||
export function useGlobalSetting<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V) : V;
|
||||
export function useGlobalSetting<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV) : V | DV {
|
||||
const [ value, setValue ] = useState(settings.getValue(key, defaultValue));
|
||||
export function useGlobalSetting<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV) : V | DV;
|
||||
|
||||
export function useGlobalSetting(key, defaultValue) {
|
||||
const [ value, setValue ] = useState(arguments.length > 1 ? settings.getValue(key, defaultValue) : settings.getValue(key));
|
||||
useEffect(() => settings.globalChangeListener(key, value => setValue(value)), []);
|
||||
|
||||
return value;
|
||||
|
|
Loading…
Reference in New Issue