Skip to content

Commit 3c48d79

Browse files
committed
update get() to return a single value for a key
1 parent 04ad767 commit 3c48d79

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

packages/browser/src/integrations/remoteconfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ const _remoteConfigIntegration = (() => {
4545

4646
return _inst.fetchAndApply();
4747
},
48-
get<T>(defaultConfig: T): T {
48+
get<T>(key: string, defaultValue: T): T {
4949
if (!_inst) {
50-
return defaultConfig;
50+
return defaultValue;
5151
}
5252

53-
return _inst.get(defaultConfig);
53+
return _inst.get(key, defaultValue);
5454
},
5555
getInternal(config: RemoteOverrideableConfig): RemoteOverrideableConfig {
5656
if (!_inst) {

packages/core/src/remoteconfig.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,33 +115,42 @@ export function remoteConfig({
115115
_transport
116116
// @ts-expect-error envelopes and such
117117
.send([[], [[{ type: 'features' }, {}]]])
118-
.then(resp => {
119-
// _lastFetch = new Date();
120-
// on success, check if cached, then do nothing
121-
if (resp.statusCode === 304) {
122-
// _state = "SUCCESS_CACHED";
123-
124-
return;
125-
}
126-
127-
// not cached...get body and send pending
128-
// @ts-expect-error resp.response not typed
129-
resp.response
130-
.json()
131-
.then((data: RemoteConfigPayload) => {
132-
// _lastFetch = new Date();
133-
_pendingConfig = data;
134-
_hasUpdate = true;
135-
136-
storage.set(defaultConfigName, data);
137-
// storage.set(`${defaultConfigName}_lastFetch`, +_lastFetch);
138-
// _state = "SUCCESS";
139-
resolve();
140-
})
141-
.catch(() => {
142-
// TODO: Error handling
143-
});
144-
})
118+
.then(
119+
resp => {
120+
// _lastFetch = new Date();
121+
// on success, check if cached, then do nothing
122+
if (resp.statusCode === 304) {
123+
// _state = "SUCCESS_CACHED";
124+
125+
return;
126+
}
127+
128+
// not cached...get body and send pending
129+
// @ts-expect-error resp.response not typed
130+
resp.response
131+
.json()
132+
.then((data: RemoteConfigPayload) => {
133+
console.log('success', data);
134+
// _lastFetch = new Date();
135+
_pendingConfig = data;
136+
_hasUpdate = true;
137+
138+
storage.set(defaultConfigName, data);
139+
// storage.set(`${defaultConfigName}_lastFetch`, +_lastFetch);
140+
// _state = "SUCCESS";
141+
resolve();
142+
})
143+
.catch(err => {
144+
console.log('catch');
145+
console.error(err);
146+
// TODO: Error handling
147+
});
148+
},
149+
err => {
150+
console.error(err);
151+
// TODO rejection
152+
},
153+
)
145154
);
146155
});
147156
}
@@ -194,8 +203,12 @@ export function remoteConfig({
194203
}
195204

196205
/** @inheritdoc */
197-
function get<T>(defaultConfig: T): T {
198-
return (_activeConfig && (_activeConfig.features as T)) || defaultConfig;
206+
function get<T>(key: string, defaultValue: T): T {
207+
if (!_activeConfig || !_activeConfig.features || !(key in _activeConfig.features)) {
208+
return defaultValue;
209+
}
210+
211+
return _activeConfig.features[key];
199212
}
200213

201214
_initialize();

packages/types/src/remoteconfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export interface RemoteConfigInterface {
2626
*/
2727
fetchAndApply: () => any;
2828
/**
29-
* Returns current configuration. Can be from user-supplied defaults, local
29+
* Returns current configuration value for a key. Can be from user-supplied defaults, local
3030
* cache, or remote configuration.
3131
*/
32-
get: <T>(defaultConfig: T) => T;
32+
get: <T>(key: string, defaultValue: T) => T;
3333
/**
3434
* Returns Sentry-internal configuration options.
3535
*/

0 commit comments

Comments
 (0)