mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-11 22:54:46 +08:00
Created config global state. Reworked WeatherSettings and WeatherWidget to use new config state.
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export * from './iconParser';
|
||||
export * from './urlParser';
|
||||
export * from './urlParser';
|
||||
export * from './searchConfig';
|
||||
24
client/src/utility/searchConfig.ts
Normal file
24
client/src/utility/searchConfig.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user