Skip to content

Commit 0fcc983

Browse files
committed
feat(remote-config, other): official onConfigUpdate API, w/Other platform support
The old API onConfigUpdated API is now deprecated but continues to work (and in fact works on Other platform as well now)
1 parent 15a0d8d commit 0fcc983

File tree

11 files changed

+664
-250
lines changed

11 files changed

+664
-250
lines changed

docs/remote-config/usage/index.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,28 +189,24 @@ in applications that attach one or more listeners for them.
189189

190190
### Known Issues
191191

192-
1. **_Handle errors / retry in callback_** During testing here in react-native-firebase, we frequently received the "config_update_not_fetched" error when performing updates and fetching them rapidly. This may not occur in normal usage but be sure to include error handling code in your callback. If this error is raised, you should be able to fetch and activate the new config template with retries after a timeout. Tracked as https://github.com/firebase/firebase-ios-sdk/issues/11462 and a fix is anticipated in firebase-ios-sdk 10.12.0
193-
1. **_iOS web socket will never close_** During testing here in react-native-firebase, we identified a problem in firebase-ios-sdk where native listeners are not removed when you attempt to unsubscribe them, resulting in more update events than expected. As a temporary workaround to avoid the issue, we create a native listener on iOS the first time you subscribe to realtime update events, and we never remove the listener, even if you unsubscribe it. That means the web socket will never close once opened. This is tracked as https://github.com/firebase/firebase-ios-sdk/issues/11458 and a fix is anticipated in firebase-ios-sdk 10.12.0
192+
1. **_Other platform requires a `fetchAndActivate` before updates come through_** During testing here in react-native-firebase and the sister project `FlutterFire`, we noticed that the firebase-js-sdk does not seem to send realtime update events through unless you have previously called `fetchAndActivate`
194193

195194
Here is an example of how to use the feature, with comments emphasizing the key points to know:
196195

197196
```js
198197
// Add a config update listener where appropriate, perhaps in app startup, or a specific app area.
199198
// Multiple listeners are supported, so listeners may be screen-specific and only handle certain keys
200199
// depending on application requirements
201-
let remoteConfigListenerUnsubscriber = remoteConfig().onConfigUpdated((event, error) => {
202-
if (error !== undefined) {
203-
console.log('remote-config listener subscription error: ' + JSON.stringify(error));
204-
} else {
205-
// Updated keys are keys that are added, removed, or changed value, metadata, or source
206-
// Note: A key is considered updated if it is different then the activated config.
207-
// If the new config is never activated, the same keys will remain in the set of
208-
// of updated keys passed to the callback on every config update
209-
console.log('remote-config updated keys: ' + JSON.stringify(event));
200+
let remoteConfigListenerUnsubscriber = onConfigUpdate(getRemoteConfig(), {
201+
next: (update) => {
202+
console.log('remote-config keys updated: ' + Array.from(update.getUpdatedKeys()));
210203

211204
// If you use realtime updates, the SDK fetches the new config for you.
212205
// However, you must activate the new config so it is in effect
213-
remoteConfig().activate();
206+
activate(getRemoteConfig());
207+
}
208+
error: (error) => {
209+
console.log('remote-config listener subscription error: ' + error);
214210
}
215211
});
216212

packages/remote-config/__tests__/remote-config.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
fetch,
3939
setDefaults,
4040
setDefaultsFromResource,
41+
onConfigUpdate,
4142
onConfigUpdated,
4243
setCustomSignals,
4344
LastFetchStatus,
@@ -234,6 +235,10 @@ describe('remoteConfig()', function () {
234235
expect(setDefaultsFromResource).toBeDefined();
235236
});
236237

238+
it('`onConfigUpdate` function is properly exposed to end user', function () {
239+
expect(onConfigUpdate).toBeDefined();
240+
});
241+
237242
it('`onConfigUpdated` function is properly exposed to end user', function () {
238243
expect(onConfigUpdated).toBeDefined();
239244
});

0 commit comments

Comments
 (0)