[config][types] Tweak types for remote config
This commit is contained in:
parent
90febd6f25
commit
3b3d013656
|
@ -1511,7 +1511,7 @@ declare module 'react-native-firebase' {
|
||||||
* The default duration is 43200 seconds (12 hours).
|
* The default duration is 43200 seconds (12 hours).
|
||||||
* To force a cache refresh call the method with a duration of 0.
|
* To force a cache refresh call the method with a duration of 0.
|
||||||
*/
|
*/
|
||||||
fetch(duration?: number): Promise<void>;
|
fetch(duration?: number): Promise<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the remote config data from Firebase, defined in the dashboard.
|
* Fetches the remote config data from Firebase, defined in the dashboard.
|
||||||
|
@ -1536,6 +1536,11 @@ declare module 'react-native-firebase' {
|
||||||
*/
|
*/
|
||||||
getKeysByPrefix(prefix?: string): Promise<Array<String>>;
|
getKeysByPrefix(prefix?: string): Promise<Array<String>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets config defaults for parameter keys and values in the default namespace config.
|
||||||
|
*/
|
||||||
|
setDefault(defaults: Object): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default values from a resource:
|
* Sets the default values from a resource:
|
||||||
* - Android: Id for the XML resource, which should be in your application's res/xml folder.
|
* - Android: Id for the XML resource, which should be in your application's res/xml folder.
|
||||||
|
|
|
@ -22,6 +22,11 @@ type NativeValue = {
|
||||||
export const MODULE_NAME = 'RNFirebaseRemoteConfig';
|
export const MODULE_NAME = 'RNFirebaseRemoteConfig';
|
||||||
export const NAMESPACE = 'config';
|
export const NAMESPACE = 'config';
|
||||||
|
|
||||||
|
type ConfigSnapshot = {
|
||||||
|
source: string,
|
||||||
|
val(): any,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Config
|
* @class Config
|
||||||
*/
|
*/
|
||||||
|
@ -44,7 +49,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_nativeValueToJS(nativeValue: NativeValue) {
|
_nativeValueToJS(nativeValue: NativeValue): ConfigSnapshot {
|
||||||
return {
|
return {
|
||||||
source: nativeValue.source,
|
source: nativeValue.source,
|
||||||
val() {
|
val() {
|
||||||
|
@ -89,7 +94,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* Call activateFetched to make fetched data available in app
|
* Call activateFetched to make fetched data available in app
|
||||||
* @returns {*|Promise.<String>}:
|
* @returns {*|Promise.<String>}:
|
||||||
*/
|
*/
|
||||||
fetch(expiration?: number) {
|
fetch(expiration?: number): Promise<string> {
|
||||||
if (expiration !== undefined) {
|
if (expiration !== undefined) {
|
||||||
getLogger(this).debug(
|
getLogger(this).debug(
|
||||||
`Fetching remote config data with expiration ${expiration.toString()}`
|
`Fetching remote config data with expiration ${expiration.toString()}`
|
||||||
|
@ -106,7 +111,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* resolves if there was a Fetched Config, and it was activated,
|
* resolves if there was a Fetched Config, and it was activated,
|
||||||
* rejects if no Fetched Config was found, or the Fetched Config was already activated.
|
* rejects if no Fetched Config was found, or the Fetched Config was already activated.
|
||||||
*/
|
*/
|
||||||
activateFetched() {
|
activateFetched(): Promise<boolean> {
|
||||||
getLogger(this).debug('Activating remote config');
|
getLogger(this).debug('Activating remote config');
|
||||||
return getNativeModule(this).activateFetched();
|
return getNativeModule(this).activateFetched();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +129,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* "source" : OneOf<String>(remoteConfigSourceRemote|remoteConfigSourceDefault|remoteConfigSourceStatic)
|
* "source" : OneOf<String>(remoteConfigSourceRemote|remoteConfigSourceDefault|remoteConfigSourceStatic)
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
getValue(key: string) {
|
getValue(key: string): Promise<ConfigSnapshot> {
|
||||||
return getNativeModule(this)
|
return getNativeModule(this)
|
||||||
.getValue(key || '')
|
.getValue(key || '')
|
||||||
.then(this._nativeValueToJS);
|
.then(this._nativeValueToJS);
|
||||||
|
@ -144,7 +149,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* "source" : OneOf<String>(remoteConfigSourceRemote|remoteConfigSourceDefault|remoteConfigSourceStatic)
|
* "source" : OneOf<String>(remoteConfigSourceRemote|remoteConfigSourceDefault|remoteConfigSourceStatic)
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
getValues(keys: Array<string>) {
|
getValues(keys: Array<string>): Promise<{ [string]: ConfigSnapshot }> {
|
||||||
return getNativeModule(this)
|
return getNativeModule(this)
|
||||||
.getValues(keys || [])
|
.getValues(keys || [])
|
||||||
.then(nativeValues => {
|
.then(nativeValues => {
|
||||||
|
@ -161,7 +166,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* @param prefix: The key prefix to look for. If prefix is nil or empty, returns all the keys.
|
* @param prefix: The key prefix to look for. If prefix is nil or empty, returns all the keys.
|
||||||
* @returns {*|Promise.<Array<String>>}
|
* @returns {*|Promise.<Array<String>>}
|
||||||
*/
|
*/
|
||||||
getKeysByPrefix(prefix?: string) {
|
getKeysByPrefix(prefix?: string): Promise<string[]> {
|
||||||
return getNativeModule(this).getKeysByPrefix(prefix);
|
return getNativeModule(this).getKeysByPrefix(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +174,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* Sets config defaults for parameter keys and values in the default namespace config.
|
* Sets config defaults for parameter keys and values in the default namespace config.
|
||||||
* @param defaults: A dictionary mapping a String key to a Object values.
|
* @param defaults: A dictionary mapping a String key to a Object values.
|
||||||
*/
|
*/
|
||||||
setDefaults(defaults: Object) {
|
setDefaults(defaults: Object): void {
|
||||||
getNativeModule(this).setDefaults(defaults);
|
getNativeModule(this).setDefaults(defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +182,7 @@ export default class RemoteConfig extends ModuleBase {
|
||||||
* Sets default configs from plist for default namespace;
|
* Sets default configs from plist for default namespace;
|
||||||
* @param resource: The plist file name or resource ID
|
* @param resource: The plist file name or resource ID
|
||||||
*/
|
*/
|
||||||
setDefaultsFromResource(resource: string | number) {
|
setDefaultsFromResource(resource: string | number): void {
|
||||||
getNativeModule(this).setDefaultsFromResource(resource);
|
getNativeModule(this).setDefaultsFromResource(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue