mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-15 07:37:37 +08:00
[config] Implement LastFetchStatus & ValueSource statics
This commit is contained in:
@@ -24,6 +24,23 @@ describe('config()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('statics', () => {
|
||||
it('LastFetchStatus', () => {
|
||||
firebase.config.LastFetchStatus.should.be.an.Object();
|
||||
firebase.config.LastFetchStatus.FAILURE.should.equal('failure');
|
||||
firebase.config.LastFetchStatus.SUCCESS.should.equal('success');
|
||||
firebase.config.LastFetchStatus.NO_FETCH_YET.should.equal('no_fetch_yet');
|
||||
firebase.config.LastFetchStatus.THROTTLED.should.equal('throttled');
|
||||
});
|
||||
|
||||
it('ValueSource', () => {
|
||||
firebase.config.ValueSource.should.be.an.Object();
|
||||
firebase.config.ValueSource.REMOTE.should.equal('remote');
|
||||
firebase.config.ValueSource.STATIC.should.equal('static');
|
||||
firebase.config.ValueSource.DEFAULT.should.equal('default');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetch()', () => {
|
||||
it('with expiration provided', () => firebase.config().fetch(0));
|
||||
it('without expiration provided', () => firebase.config().fetch());
|
||||
@@ -234,7 +251,6 @@ describe('config()', () => {
|
||||
|
||||
describe('setDefaultsFromResource()', () => {
|
||||
it('sets defaults from remote_config_resource_test file', async () => {
|
||||
await Utils.sleep(10000);
|
||||
await firebase.config().setDefaultsFromResource('remote_config_resource_test');
|
||||
const config = await firebase.config().getValues(['company']);
|
||||
config.company.source.should.equal('default');
|
||||
|
||||
122
packages/config/lib/index.d.ts
vendored
122
packages/config/lib/index.d.ts
vendored
@@ -58,7 +58,123 @@ import {
|
||||
* @firebase config
|
||||
*/
|
||||
export namespace Config {
|
||||
export interface Statics {}
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus;
|
||||
* ```
|
||||
*/
|
||||
export interface LastFetchStatus {
|
||||
/**
|
||||
* A value indicating that the last fetch was successful.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.SUCCESS;
|
||||
* ```
|
||||
*/
|
||||
SUCCESS: 'success';
|
||||
|
||||
/**
|
||||
* A value indicating that the last fetch failed.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.FAILURE;
|
||||
* ```
|
||||
*/
|
||||
FAILURE: 'failure';
|
||||
|
||||
/**
|
||||
* A value indicating that the last fetch was throttled.
|
||||
*
|
||||
* This usually occurs when calling fetch often with a low expiration duration.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.THROTTLED;
|
||||
* ```
|
||||
*/
|
||||
THROTTLED: 'throttled';
|
||||
|
||||
/**
|
||||
* A value indicating that no fetches have occurred yet.
|
||||
*
|
||||
* This usually means you've not called fetch yet.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.NO_FETCH_YET;
|
||||
* ```
|
||||
*/
|
||||
NO_FETCH_YET: 'no_fetch_yet';
|
||||
}
|
||||
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigValue.source to determine the value source.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource;
|
||||
* ```
|
||||
*/
|
||||
export interface ValueSource {
|
||||
/**
|
||||
* If the value was retrieved from the server.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource.REMOTE;
|
||||
* ```
|
||||
*/
|
||||
REMOTE: 'remote';
|
||||
/**
|
||||
* If the value was set as a default value.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource.DEFAULT;
|
||||
* ```
|
||||
*/
|
||||
DEFAULT: 'default';
|
||||
/**
|
||||
* If no value was found and a static default value was returned instead.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource.STATIC;
|
||||
* ```
|
||||
*/
|
||||
STATIC: 'static';
|
||||
}
|
||||
|
||||
/**
|
||||
* Firebase Remote Config statics.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config;
|
||||
* ```
|
||||
*/
|
||||
export interface Statics {
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigValue.source to determine the value source.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource;
|
||||
* ```
|
||||
*/
|
||||
ValueSource: ValueSource;
|
||||
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus;
|
||||
* ```
|
||||
*/
|
||||
LastFetchStatus: LastFetchStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* An Interface representing a Remote Config value.
|
||||
@@ -71,6 +187,8 @@ export namespace Config {
|
||||
* - `default`: If the value was set as a default value.
|
||||
* - `static`: If no value was found and a static default value was returned instead.
|
||||
*
|
||||
* See the `ValueSource` statics definition.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
@@ -156,6 +274,8 @@ export namespace Config {
|
||||
isDeveloperModeEnabled: boolean;
|
||||
/**
|
||||
* The status of the latest Remote Config fetch action.
|
||||
*
|
||||
* See the `LastFetchStatus` statics definition.
|
||||
*/
|
||||
lastFetchStatus: 'success' | 'failure' | 'no_fetch_yet' | 'throttled';
|
||||
}
|
||||
|
||||
@@ -32,7 +32,19 @@ import {
|
||||
|
||||
import version from './version';
|
||||
|
||||
const statics = {};
|
||||
const statics = {
|
||||
LastFetchStatus: {
|
||||
SUCCESS: 'success',
|
||||
FAILURE: 'failure',
|
||||
THROTTLED: 'throttled',
|
||||
NO_FETCH_YET: 'no_fetch_yet',
|
||||
},
|
||||
ValueSource: {
|
||||
REMOTE: 'remote',
|
||||
DEFAULT: 'default',
|
||||
STATIC: 'static',
|
||||
},
|
||||
};
|
||||
|
||||
const namespace = 'config';
|
||||
|
||||
|
||||
@@ -18,7 +18,123 @@
|
||||
|
||||
import type { ReactNativeFirebaseModule } from '@react-native-firebase/app-types/index.js.flow';
|
||||
|
||||
export interface Statics {}
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus;
|
||||
* ```
|
||||
*/
|
||||
export interface LastFetchStatus {
|
||||
/**
|
||||
* A value indicating that the last fetch was successful.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.SUCCESS;
|
||||
* ```
|
||||
*/
|
||||
SUCCESS: 'success';
|
||||
|
||||
/**
|
||||
* A value indicating that the last fetch failed.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.FAILURE;
|
||||
* ```
|
||||
*/
|
||||
FAILURE: 'failure';
|
||||
|
||||
/**
|
||||
* A value indicating that the last fetch was throttled.
|
||||
*
|
||||
* This usually occurs when calling fetch often with a low expiration duration.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.THROTTLED;
|
||||
* ```
|
||||
*/
|
||||
THROTTLED: 'throttled';
|
||||
|
||||
/**
|
||||
* A value indicating that no fetches have occurred yet.
|
||||
*
|
||||
* This usually means you've not called fetch yet.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus.NO_FETCH_YET;
|
||||
* ```
|
||||
*/
|
||||
NO_FETCH_YET: 'no_fetch_yet';
|
||||
}
|
||||
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigValue.source to determine the value source.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource;
|
||||
* ```
|
||||
*/
|
||||
export interface ValueSource {
|
||||
/**
|
||||
* If the value was retrieved from the server.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource.REMOTE;
|
||||
* ```
|
||||
*/
|
||||
REMOTE: 'remote';
|
||||
/**
|
||||
* If the value was set as a default value.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource.DEFAULT;
|
||||
* ```
|
||||
*/
|
||||
DEFAULT: 'default';
|
||||
/**
|
||||
* If no value was found and a static default value was returned instead.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource.STATIC;
|
||||
* ```
|
||||
*/
|
||||
STATIC: 'static';
|
||||
}
|
||||
|
||||
/**
|
||||
* Firebase Remote Config statics.
|
||||
*
|
||||
* ```js
|
||||
* firebase.config;
|
||||
* ```
|
||||
*/
|
||||
export interface Statics {
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigValue.source to determine the value source.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.ValueSource;
|
||||
* ```
|
||||
*/
|
||||
ValueSource: ValueSource;
|
||||
|
||||
/**
|
||||
* A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status.
|
||||
*
|
||||
* #### Example
|
||||
*
|
||||
* ```js
|
||||
* firebase.config.LastFetchStatus;
|
||||
* ```
|
||||
*/
|
||||
LastFetchStatus: LastFetchStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* An Interface representing a Remote Config value
|
||||
|
||||
Reference in New Issue
Block a user