Created config global state. Reworked WeatherSettings and WeatherWidget to use new config state.

This commit is contained in:
unknown
2021-06-13 00:16:57 +02:00
parent a5504e6e80
commit d257fbf9a3
15 changed files with 214 additions and 88 deletions

View File

@@ -1,2 +1,3 @@
export * from './iconParser';
export * from './urlParser';
export * from './urlParser';
export * from './searchConfig';

View File

@@ -0,0 +1,24 @@
import { store } from '../store/store';
/**
* Search config store with given key
* @param key Config pair key to search
* @param _default Value to return if key is not found
*/
export const searchConfig = (key: string, _default: any)=> {
const state = store.getState();
const pair = state.config.config.find(p => p.key === key);
if (pair) {
if (pair.valueType === 'number') {
return parseFloat(pair.value);
} else if (pair.valueType === 'boolean') {
return parseInt(pair.value);
} else {
return pair.value;
}
} else {
return _default;
}
}