Skip to content

Commit 26f615f

Browse files
author
Kevin Elko
committed
Initial impl of config state hydration
1 parent add6e90 commit 26f615f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/remote-config/src/api.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
RemoteConfig,
2222
Value
2323
} from './public_types';
24-
import { RemoteConfigAbortSignal } from './client/remote_config_fetch_client';
24+
import { RemoteConfigAbortSignal, FetchResponse } from './client/remote_config_fetch_client';
2525
import { RC_COMPONENT_NAME } from './constants';
2626
import { ErrorCode, hasErrorCode } from './errors';
2727
import { RemoteConfig as RemoteConfigImpl } from './remote_config';
@@ -131,6 +131,23 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
131131
}
132132
}
133133

134+
/**
135+
* Manually hydrates the config state without making an async fetch request.
136+
* @param remoteConfig - The {@link RemoteConfig} instance.
137+
* @param fetchResponse - The fetchResponse containing the config values and eTag
138+
* with which to hydrate the internal state.
139+
*/
140+
export async function setRenderedConfig(remoteConfig: RemoteConfig, fetchResponse: FetchResponse) {
141+
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
142+
await Promise.all([
143+
rc._storage.setLastSuccessfulFetchResponse(fetchResponse),
144+
rc._storage.setActiveConfigEtag(fetchResponse.eTag || ''),
145+
rc._storageCache.setLastSuccessfulFetchTimestampMillis(Date.now()),
146+
rc._storageCache.setLastFetchStatus('success'),
147+
rc._storageCache.setActiveConfig(fetchResponse.config || {}),
148+
]);
149+
}
150+
134151
/**
135152
* Gets all config.
136153
*

packages/remote-config/src/client/remote_config_fetch_client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export interface FetchRequest {
107107
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
108108
* use case.
109109
*/
110+
// TODO - should we move this public_types.ts?
110111
export interface FetchResponse {
111112
/**
112113
* The HTTP status, which is useful for differentiating success responses with data from

0 commit comments

Comments
 (0)