Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 5d88cfd

Browse files
prepare 4.2.2 release (#84)
1 parent 8fb257b commit 5d88cfd

File tree

4 files changed

+55
-62
lines changed

4 files changed

+55
-62
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the LaunchDarkly React Native SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
44

5+
## [4.0.4] - 2021-06-02
6+
### Fixed:
7+
- iOS: Fixed an issue where an exception was thrown when calling `LDClient.configure` with an optional `timeout` ([#80](https://github.com/launchdarkly/react-native-client-sdk/issues/80)).
8+
59
## [4.2.1] - 2021-06-01
610
### Fixed:
711
- iOS: Fixed an issue where an exception was thrown when calling `LDClient.configure` with an optional `timeout` ([#80](https://github.com/launchdarkly/react-native-client-sdk/issues/80)).
@@ -10,15 +14,13 @@ All notable changes to the LaunchDarkly React Native SDK will be documented in t
1014
- Android: Fixed an issue where the promise for `LDClient.configure` could be resolved before the client had finished initializing when not providing the optional `timeout` parameter.
1115
- Android: Fixed an issue where `LDClient.allFlags` would reject the promise when the client was configured but not yet initialized, rather than resolving with any cached flags.
1216

13-
1417
## [4.2.0] - 2021-05-19
1518
### Added:
1619
- `LDUser` now has an optional `secondary` attribute to match other LaunchDarkly SDKs. For more on the behavior of this attribute see [the documentation on targeting users](https://docs.launchdarkly.com/home/managing-flags/targeting-users).
1720
- Support for multiple LaunchDarkly projects or environments. Each set of feature flags associated with a mobile key is called an environment. ([#10](https://github.com/launchdarkly/react-native-client-sdk/issues/10))
1821
- `secondaryMobileKeys` is now a config option which allows a mapping of names to the SDK keys for each additional environment. `mobileKey` is still required, and represents the primary environment.
1922
- Many methods including variations, track, and listeners now support an optional `environment` parameter to evaluate the method against the given `environment`.
2023

21-
2224
## [4.1.2] - 2021-04-28
2325
### Fixed:
2426
- The `LDEvaluationReasonErrorKind`, `LDEvaluationReasonKind`, `LDConnectionMode`, and `LDFailureReason` enum TypeScript types were undefined when evaluated at runtime due to being defined in an ambient context. This was also fixed in SDK version 4.0.3 with React Native 0.63 compatibility.

android/src/main/java/com/launchdarkly/reactnative/LaunchdarklyReactNativeClientModule.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,13 @@ private String envConcat(String environment, String identifier) {
902902

903903
@ReactMethod
904904
public void registerFeatureFlagListener(final String flagKey, final String environment) {
905-
FeatureFlagChangeListener listener = new FeatureFlagChangeListener() {
905+
final String multiListenerId = envConcat(environment, flagKey);
906+
final FeatureFlagChangeListener listener = new FeatureFlagChangeListener() {
906907
@Override
907908
public void onFeatureFlagChange(String flagKey) {
908909
WritableMap result = Arguments.createMap();
909-
result.putString("flagKey", envConcat(environment, flagKey));
910+
result.putString("flagKey", flagKey);
911+
result.putString("listenerId", multiListenerId);
910912

911913
getReactApplicationContext()
912914
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@@ -924,10 +926,11 @@ public void onFeatureFlagChange(String flagKey) {
924926

925927
@ReactMethod
926928
public void unregisterFeatureFlagListener(String flagKey, String environment) {
929+
String multiListenerId = envConcat(environment, flagKey);
927930
try {
928-
if (listeners.containsKey(flagKey)) {
929-
LDClient.getForMobileKey(environment).unregisterFeatureFlagListener(flagKey, listeners.get(flagKey));
930-
listeners.remove(flagKey);
931+
if (listeners.containsKey(multiListenerId)) {
932+
LDClient.getForMobileKey(environment).unregisterFeatureFlagListener(flagKey, listeners.get(multiListenerId));
933+
listeners.remove(multiListenerId);
931934
}
932935
} catch (Exception e) {
933936
Timber.w(e);
@@ -936,12 +939,13 @@ public void unregisterFeatureFlagListener(String flagKey, String environment) {
936939

937940
@ReactMethod
938941
public void registerCurrentConnectionModeListener(final String listenerId, final String environment) {
942+
final String multiListenerId = envConcat(environment, listenerId);
939943
LDStatusListener listener = new LDStatusListener() {
940944
@Override
941945
public void onConnectionModeChanged(ConnectionInformation connectionInfo) {
942946
WritableMap result = Arguments.createMap();
943947
result.putString("connectionMode", gson.toJson(connectionInfo));
944-
result.putString("listenerId", envConcat(environment, listenerId));
948+
result.putString("listenerId", multiListenerId);
945949

946950
getReactApplicationContext()
947951
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@@ -954,7 +958,7 @@ public void onInternalFailure(LDFailure ldFailure) {}
954958

955959
try {
956960
LDClient.getForMobileKey(environment).registerStatusListener(listener);
957-
connectionModeListeners.put(listenerId, listener);
961+
connectionModeListeners.put(multiListenerId, listener);
958962
} catch (Exception e) {
959963
Timber.w(e);
960964
}
@@ -963,9 +967,10 @@ public void onInternalFailure(LDFailure ldFailure) {}
963967
@ReactMethod
964968
public void unregisterCurrentConnectionModeListener(String listenerId, String environment) {
965969
try {
966-
if (connectionModeListeners.containsKey(listenerId)) {
967-
LDClient.getForMobileKey(environment).unregisterStatusListener(connectionModeListeners.get(listenerId));
968-
connectionModeListeners.remove(listenerId);
970+
String multiListenerId = envConcat(environment, listenerId);
971+
if (connectionModeListeners.containsKey(multiListenerId)) {
972+
LDClient.getForMobileKey(environment).unregisterStatusListener(connectionModeListeners.get(multiListenerId));
973+
connectionModeListeners.remove(multiListenerId);
969974
}
970975
} catch (Exception e) {
971976
Timber.w(e);
@@ -974,12 +979,13 @@ public void unregisterCurrentConnectionModeListener(String listenerId, String en
974979

975980
@ReactMethod
976981
public void registerAllFlagsListener(final String listenerId, final String environment) {
982+
final String multiListenerId = envConcat(environment, listenerId);
977983
LDAllFlagsListener listener = new LDAllFlagsListener() {
978984
@Override
979985
public void onChange(List<String> flagKeys) {
980986
WritableMap result = Arguments.createMap();
981987
result.putString("flagKeys", gson.toJson(flagKeys));
982-
result.putString("listenerId", envConcat(environment, listenerId));
988+
result.putString("listenerId", multiListenerId);
983989

984990
getReactApplicationContext()
985991
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@@ -989,7 +995,7 @@ public void onChange(List<String> flagKeys) {
989995

990996
try {
991997
LDClient.getForMobileKey(environment).registerAllFlagsListener(listener);
992-
allFlagsListeners.put(listenerId, listener);
998+
allFlagsListeners.put(multiListenerId, listener);
993999
} catch (Exception e) {
9941000
Timber.w(e);
9951001
}
@@ -998,9 +1004,10 @@ public void onChange(List<String> flagKeys) {
9981004
@ReactMethod
9991005
public void unregisterAllFlagsListener(String listenerId, String environment) {
10001006
try {
1001-
if (allFlagsListeners.containsKey(listenerId)) {
1002-
LDClient.getForMobileKey(environment).unregisterAllFlagsListener(allFlagsListeners.get(listenerId));
1003-
allFlagsListeners.remove(listenerId);
1007+
String multiListenerId = envConcat(environment, listenerId);
1008+
if (allFlagsListeners.containsKey(multiListenerId)) {
1009+
LDClient.getForMobileKey(environment).unregisterAllFlagsListener(allFlagsListeners.get(multiListenerId));
1010+
allFlagsListeners.remove(multiListenerId);
10041011
}
10051012
} catch (Exception e) {
10061013
Timber.w(e);

index.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ export default class LDClient {
227227

228228
_flagUpdateListener(changedFlag) {
229229
const flagKey = changedFlag.flagKey;
230-
if (this.flagListeners.hasOwnProperty(flagKey)) {
231-
let listeners = this.flagListeners[flagKey];
230+
const listenerId = changedFlag.listenerId;
231+
if (this.flagListeners.hasOwnProperty(listenerId)) {
232+
let listeners = this.flagListeners[listenerId];
232233
for (const listener of listeners) {
233234
listener(flagKey);
234235
}
@@ -238,20 +239,16 @@ export default class LDClient {
238239
_allFlagsUpdateListener(changedFlags) {
239240
const flagKeys = changedFlags.flagKeys;
240241
const listenerId = changedFlags.listenerId;
241-
for (const [key, value] of Object.entries(this.allFlagsListeners)) {
242-
if (key == listenerId) {
243-
key(flagKeys);
244-
}
242+
if (this.allFlagsListeners.hasOwnProperty(listenerId)) {
243+
this.allFlagsListeners[listenerId](flagKeys);
245244
}
246245
}
247246

248247
_connectionModeUpdateListener(connectionStatus) {
249248
const connectionMode = connectionStatus.connectionMode;
250249
const listenerId = connectionStatus.listenerId;
251-
for (const [key, value] of Object.entries(this.connectionModeListeners)) {
252-
if (key == listenerId) {
253-
key(connectionMode);
254-
}
250+
if (this.connectionModeListeners.hasOwnProperty(listenerId)) {
251+
this.connectionModeListeners[listenerId](connectionMode);
255252
}
256253
}
257254

@@ -296,15 +293,15 @@ export default class LDClient {
296293
return;
297294
}
298295
const env = environment !== undefined ? environment : "default";
299-
const multiListenerId = this._envConcat(env, flagKey);
296+
const multiListenerId = this._envConcat(env, listenerId);
300297

301298
this.connectionModeListeners[multiListenerId] = callback;
302299
LaunchdarklyReactNativeClient.registerCurrentConnectionModeListener(listenerId, env);
303300
}
304301

305302
unregisterCurrentConnectionModeListener(listenerId, environment) {
306303
const env = environment !== undefined ? environment : "default";
307-
const multiListenerId = this._envConcat(env, flagKey);
304+
const multiListenerId = this._envConcat(env, listenerId);
308305
if (!this.connectionModeListeners.hasOwnProperty(multiListenerId)) {
309306
return;
310307
}
@@ -318,15 +315,15 @@ export default class LDClient {
318315
return;
319316
}
320317
const env = environment !== undefined ? environment : "default";
321-
const multiListenerId = this._envConcat(env, flagKey);
318+
const multiListenerId = this._envConcat(env, listenerId);
322319

323320
this.allFlagsListeners[multiListenerId] = callback;
324321
LaunchdarklyReactNativeClient.registerAllFlagsListener(listenerId, env);
325322
}
326323

327324
unregisterAllFlagsListener(listenerId, environment) {
328325
const env = environment !== undefined ? environment : "default";
329-
const multiListenerId = this._envConcat(env, flagKey);
326+
const multiListenerId = this._envConcat(env, listenerId);
330327
if (!this.allFlagsListeners.hasOwnProperty(multiListenerId)) {
331328
return;
332329
}

ios/LaunchdarklyReactNativeClient.swift

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -541,43 +541,34 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
541541
}
542542

543543
@objc func registerFeatureFlagListener(_ flagKey: String, environment: String) -> Void {
544-
let flagChangeOwner = flagKey as LDObserverOwner
545-
if listenerKeys[flagKey] == nil {
546-
listenerKeys[flagKey] = flagChangeOwner
547-
} else {
548-
return
549-
}
550-
LDClient.get(environment: environment)!.observe(keys: [flagKey], owner: flagChangeOwner, handler: { (changedFlags) in
551-
if changedFlags[flagKey] != nil && self.bridge != nil {
552-
self.sendEvent(withName: self.FLAG_PREFIX, body: ["flagKey": self.envConcat(environment: environment, identifier: flagKey)])
544+
let multiListenerId = envConcat(environment: environment, identifier: flagKey)
545+
let flagChangeOwner = multiListenerId as LDObserverOwner
546+
listenerKeys[multiListenerId] = flagChangeOwner
547+
LDClient.get(environment: environment)!.observe(key: flagKey, owner: flagChangeOwner, handler: { changedFlag in
548+
if self.bridge != nil {
549+
self.sendEvent(withName: self.FLAG_PREFIX, body: ["flagKey": changedFlag.key, "listenerId": multiListenerId])
553550
}
554551
})
555552
}
556553

557554
private func unregisterListener(_ key: String, _ environment: String) -> Void {
558-
let owner = key as LDObserverOwner
559-
if listenerKeys[key] != nil {
560-
listenerKeys.removeValue(forKey: key)
561-
} else {
562-
return
555+
let multiListenerId = envConcat(environment: environment, identifier: key)
556+
let owner = multiListenerId as LDObserverOwner
557+
if listenerKeys.removeValue(forKey: multiListenerId) != nil {
558+
LDClient.get(environment: environment)!.stopObserving(owner: owner)
563559
}
564-
LDClient.get(environment: environment)!.stopObserving(owner: owner)
565560
}
566561

567562
@objc func unregisterFeatureFlagListener(_ flagKey: String, environment: String) -> Void {
568563
unregisterListener(flagKey, environment)
569564
}
570565

571566
@objc func registerCurrentConnectionModeListener(_ listenerId: String, environment: String) -> Void {
572-
let currentConnectionModeOwner = listenerId as LDObserverOwner
573-
if listenerKeys[listenerId] == nil {
574-
listenerKeys.removeValue(forKey: listenerId)
575-
} else {
576-
return
577-
}
578-
LDClient.get(environment: environment)!.observeCurrentConnectionMode(owner: currentConnectionModeOwner, handler: { (connectionMode) in
567+
let multiListenerId = envConcat(environment: environment, identifier: listenerId)
568+
let currentConnectionModeOwner = multiListenerId as LDObserverOwner
569+
LDClient.get(environment: environment)!.observeCurrentConnectionMode(owner: currentConnectionModeOwner, handler: { connectionMode in
579570
if self.bridge != nil {
580-
self.sendEvent(withName: self.CONNECTION_MODE_PREFIX, body: ["connectionMode": connectionMode, "listenerId": self.envConcat(environment: environment, identifier: listenerId)])
571+
self.sendEvent(withName: self.CONNECTION_MODE_PREFIX, body: ["connectionMode": connectionMode, "listenerId": multiListenerId])
581572
}
582573
})
583574
}
@@ -587,15 +578,11 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
587578
}
588579

589580
@objc func registerAllFlagsListener(_ listenerId: String, environment: String) -> Void {
590-
let flagChangeOwner = listenerId as LDObserverOwner
591-
if listenerKeys[listenerId] == nil {
592-
listenerKeys[listenerId] = flagChangeOwner
593-
} else {
594-
return
595-
}
596-
LDClient.get(environment: environment)!.observeAll(owner: flagChangeOwner, handler: { (changedFlags) in
581+
let multiListenerId = envConcat(environment: environment, identifier: listenerId)
582+
let flagChangeOwner = multiListenerId as LDObserverOwner
583+
LDClient.get(environment: environment)!.observeAll(owner: flagChangeOwner, handler: { changedFlags in
597584
if self.bridge != nil {
598-
self.sendEvent(withName: self.ALL_FLAGS_PREFIX, body: ["flagKeys": changedFlags.keys.description, "listenerId": self.envConcat(environment: environment, identifier: listenerId)])
585+
self.sendEvent(withName: self.ALL_FLAGS_PREFIX, body: ["flagKeys": Array(changedFlags.keys), "listenerId": multiListenerId])
599586
}
600587
})
601588
}

0 commit comments

Comments
 (0)