File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
packages/remote-config/src Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import {
21
21
RemoteConfig ,
22
22
Value
23
23
} from './public_types' ;
24
- import { RemoteConfigAbortSignal } from './client/remote_config_fetch_client' ;
24
+ import { RemoteConfigAbortSignal , FetchResponse } from './client/remote_config_fetch_client' ;
25
25
import { RC_COMPONENT_NAME } from './constants' ;
26
26
import { ErrorCode , hasErrorCode } from './errors' ;
27
27
import { RemoteConfig as RemoteConfigImpl } from './remote_config' ;
@@ -131,6 +131,23 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
131
131
}
132
132
}
133
133
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
+
134
151
/**
135
152
* Gets all config.
136
153
*
Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ export interface FetchRequest {
107
107
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
108
108
* use case.
109
109
*/
110
+ // TODO - should we move this public_types.ts?
110
111
export interface FetchResponse {
111
112
/**
112
113
* The HTTP status, which is useful for differentiating success responses with data from
You can’t perform that action at this time.
0 commit comments