All files / src Config.js

100% Statements 14/14
94.74% Branches 18/19
100% Functions 4/4
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41          1x                     1x       5x   5x 4x       3x   3x 2x       4x   4x 3x      
/**
 * @providesModule react-native-bridge-firebase/Config
 */
import RNBridgeFirebase from './RNBridgeFirebase';
 
const { CONFIG_SOURCE } = RNBridgeFirebase;
 
export default class Config {
 
  static EVENT = RNBridgeFirebase.EVENT;
 
  static ERROR = RNBridgeFirebase.ERROR;
 
  static def = {}
 
  static setDefault(data: Object = {}) {
    Config.def = data;
  }
 
  static async getString(name: String, def: String = '') {
    const config = await RNBridgeFirebase.getStringConfig(name);
 
    if (config.source === CONFIG_SOURCE.REMOTE) return config.value;
    return def || Config.def[name] || '';
  }
 
  static async getNumber(name: String, def: Number = 0) {
    const config = await RNBridgeFirebase.getNumberConfig(name);
 
    if (config.source === CONFIG_SOURCE.REMOTE) return config.value;
    return def || Config.def[name] || 0;
  }
 
  static async getBoolean(name: String, def: Boolean = false) {
    const config = await RNBridgeFirebase.getBooleanConfig(name);
 
    if (config.source === CONFIG_SOURCE.REMOTE) return config.value;
    return def || Config.def[name] || false;
  }
}