Skip to content

Commit fdc3a22

Browse files
committed
implement interop API for rc-exp
1 parent ef7ca63 commit fdc3a22

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages-exp/remote-config-exp/src/api.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { ErrorCode, hasErrorCode } from './errors';
2727
import { RemoteConfig as RemoteConfigImpl } from './remote_config';
2828
import { Value as ValueImpl } from './value';
2929
import { LogLevel as FirebaseLogLevel } from '@firebase/logger';
30+
import { getModularInstance } from '@firebase/util';
3031

3132
/**
3233
*
@@ -36,6 +37,7 @@ import { LogLevel as FirebaseLogLevel } from '@firebase/logger';
3637
* @public
3738
*/
3839
export function getRemoteConfig(app: FirebaseApp): RemoteConfig {
40+
app = getModularInstance(app);
3941
const rcProvider = _getProvider(app, RC_COMPONENT_NAME);
4042
return rcProvider.getImmediate();
4143
}
@@ -49,7 +51,7 @@ export function getRemoteConfig(app: FirebaseApp): RemoteConfig {
4951
* @public
5052
*/
5153
export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
52-
const rc = remoteConfig as RemoteConfigImpl;
54+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
5355
const [lastSuccessfulFetchResponse, activeConfigEtag] = await Promise.all([
5456
rc._storage.getLastSuccessfulFetchResponse(),
5557
rc._storage.getActiveConfigEtag()
@@ -79,7 +81,7 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
7981
* @public
8082
*/
8183
export function ensureInitialized(remoteConfig: RemoteConfig): Promise<void> {
82-
const rc = remoteConfig as RemoteConfigImpl;
84+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
8385
if (!rc._initializePromise) {
8486
rc._initializePromise = rc._storageCache.loadFromStorage().then(() => {
8587
rc._isInitializationComplete = true;
@@ -94,7 +96,7 @@ export function ensureInitialized(remoteConfig: RemoteConfig): Promise<void> {
9496
* @public
9597
*/
9698
export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
97-
const rc = remoteConfig as RemoteConfigImpl;
99+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
98100
// Aborts the request after the given timeout, causing the fetch call to
99101
// reject with an AbortError.
100102
//
@@ -138,7 +140,7 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
138140
* @public
139141
*/
140142
export function getAll(remoteConfig: RemoteConfig): Record<string, Value> {
141-
const rc = remoteConfig as RemoteConfigImpl;
143+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
142144
return getAllKeys(
143145
rc._storageCache.getActiveConfig(),
144146
rc.defaultConfig
@@ -160,7 +162,7 @@ export function getAll(remoteConfig: RemoteConfig): Record<string, Value> {
160162
* @public
161163
*/
162164
export function getBoolean(remoteConfig: RemoteConfig, key: string): boolean {
163-
return getValue(remoteConfig, key).asBoolean();
165+
return getValue(getModularInstance(remoteConfig), key).asBoolean();
164166
}
165167

166168
/**
@@ -176,7 +178,7 @@ export function getBoolean(remoteConfig: RemoteConfig, key: string): boolean {
176178
* @public
177179
*/
178180
export function getNumber(remoteConfig: RemoteConfig, key: string): number {
179-
return getValue(remoteConfig, key).asNumber();
181+
return getValue(getModularInstance(remoteConfig), key).asNumber();
180182
}
181183

182184
/**
@@ -191,7 +193,7 @@ export function getNumber(remoteConfig: RemoteConfig, key: string): number {
191193
* @public
192194
*/
193195
export function getString(remoteConfig: RemoteConfig, key: string): string {
194-
return getValue(remoteConfig, key).asString();
196+
return getValue(getModularInstance(remoteConfig), key).asString();
195197
}
196198

197199
/**
@@ -205,7 +207,7 @@ export function getString(remoteConfig: RemoteConfig, key: string): string {
205207
* @public
206208
*/
207209
export function getValue(remoteConfig: RemoteConfig, key: string): Value {
208-
const rc = remoteConfig as RemoteConfigImpl;
210+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
209211
if (!rc._isInitializationComplete) {
210212
rc._logger.debug(
211213
`A value was requested for key "${key}" before SDK initialization completed.` +
@@ -237,7 +239,7 @@ export function setLogLevel(
237239
remoteConfig: RemoteConfig,
238240
logLevel: RemoteConfigLogLevel
239241
): void {
240-
const rc = remoteConfig as RemoteConfigImpl;
242+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
241243
switch (logLevel) {
242244
case 'debug':
243245
rc._logger.logLevel = FirebaseLogLevel.DEBUG;

packages-exp/remote-config-exp/src/api2.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { RemoteConfig } from './public_types';
1919
import { activate, fetchConfig } from './api';
20+
import { getModularInstance } from '@firebase/util';
2021

2122
// This API is put in a separate file, so we can stub fetchConfig and activate in tests.
2223
// It's not possible to stub standalone functions from the same module.
@@ -34,6 +35,7 @@ import { activate, fetchConfig } from './api';
3435
export async function fetchAndActivate(
3536
remoteConfig: RemoteConfig
3637
): Promise<boolean> {
38+
remoteConfig = getModularInstance(remoteConfig);
3739
await fetchConfig(remoteConfig);
3840
return activate(remoteConfig);
3941
}

0 commit comments

Comments
 (0)