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

Commit

Permalink
Version 2.2.0 (#32)
Browse files Browse the repository at this point in the history
* Changed start to startCompleteWhenFlagsReceived, serialize EvaluationDetail to NSDictionary, bump version numbers

* Added evaluationReasons config option, removed unnecessary iOS serialization

* Fixed Android config enum syntax error

* Serialize iOS and Android EvaluationDetail

* Parsing object to JSON to JSONObject to WriteableMap in Android native

* Fixed jsonString type

* Revert version number bump

* Added static Gson object, simplified EvaluationDetail parsing on Android native

* Remove invalid closing p tag from Android native JavaDoc
  • Loading branch information
torchhound authored Jan 25, 2020
1 parent 1e96bc5 commit b94d706
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LaunchDarkly overview
Supported versions
-------------------------

This SDK is compatible with React Native 0.61.2 and Xcode 10.2.1 and is tested in Android 27 and iOS 12.2. Earlier versions of this SDK are compatible with prior versions of React Native, Android, and iOS.
This SDK is compatible with React Native 0.61.2 and Xcode 10.2.1 and is tested in Android 27 and iOS 12.4. Earlier versions of this SDK are compatible with prior versions of React Native, Android, and iOS.

Getting started
---------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class LaunchdarklyReactNativeClientModule extends ReactContextBaseJavaMod
* option, see @see ConfigEntryType for more. The internal setter is a String name of the setter
* method used to pass the parsed configuration value into a LDConfig builder used for LDClient
* setup.
* </p>
*/
enum ConfigMapping {
CONFIG_MOBILE_KEY("mobileKey", ConfigEntryType.String, "setMobileKey"),
Expand All @@ -80,7 +79,8 @@ enum ConfigMapping {
CONFIG_STREAM("stream", ConfigEntryType.Boolean, "setStream"),
CONFIG_DISABLE_BACKGROUND_UPDATING("disableBackgroundUpdating", ConfigEntryType.Boolean, "setDisableBackgroundUpdating"),
CONFIG_OFFLINE("offline", ConfigEntryType.Boolean, "setOffline"),
CONFIG_PRIVATE_ATTRIBUTES("privateAttributeNames", ConfigEntryType.StringSet, "setPrivateAttributeNames");
CONFIG_PRIVATE_ATTRIBUTES("privateAttributeNames", ConfigEntryType.StringSet, "setPrivateAttributeNames"),
CONFIG_EVALUATION_REASONS("evaluationReasons", ConfigEntryType.Boolean, "setEvaluationReasons");

final String key;
final ConfigEntryType type;
Expand Down Expand Up @@ -115,7 +115,6 @@ void loadFromMap(ReadableMap map, LDConfig.Builder builder) {
* ReadableMap as well as any additional conversion needed before setting the internal LDUser
* option, @see ConfigEntryType for more. The internal setter is a String name of the setter
* method used to pass the parsed configuration value into a LDUser builder.
* </p>
*/
enum UserConfigMapping {
USER_ANONYMOUS("anonymous", ConfigEntryType.Boolean, "anonymous", null),
Expand Down Expand Up @@ -164,6 +163,8 @@ void loadFromMap(ReadableMap map, LDUser.Builder builder, Set<String> privateAtt
private Map<String, LDStatusListener> connectionModeListeners = new HashMap<>();
private Map<String, LDAllFlagsListener> allFlagsListeners = new HashMap<>();

private static Gson gson = new Gson();

public LaunchdarklyReactNativeClientModule(ReactApplicationContext reactContext) {
super(reactContext);
}
Expand Down Expand Up @@ -267,7 +268,6 @@ public void run() {
*
* <p>
* This will look for all configuration values specified in {@link ConfigMapping}.
* </p>
*
* @param options A ReadableMap of configuration options
* @return A LDConfig.Builder configured with options
Expand All @@ -287,7 +287,6 @@ private LDConfig.Builder configBuild(ReadableMap options) {
*
* <p>
* This will look for all configuration values specified in {@link UserConfigMapping}.
* </p>
*
* @param options A ReadableMap of configuration options
* @return A LDUser.Builder configured with options
Expand Down Expand Up @@ -567,7 +566,10 @@ public void boolVariationDetail(String flagKey, Promise promise) {
@ReactMethod
public void boolVariationDetailFallback(String flagKey, Boolean fallback, Promise promise) {
try {
promise.resolve(ldClient.boolVariationDetail(flagKey, fallback));
EvaluationDetail<Boolean> detailResult = ldClient.boolVariationDetail(flagKey, fallback);
JsonObject jsonObject = gson.toJsonTree(detailResult).getAsJsonObject();
WritableMap detailMap = fromJsonObject(jsonObject);
promise.resolve(detailMap);
} catch (Exception e) {
promise.resolve(fallback);
}
Expand All @@ -581,7 +583,10 @@ public void intVariationDetail(String flagKey, Promise promise) {
@ReactMethod
public void intVariationDetailFallback(String flagKey, Integer fallback, Promise promise) {
try {
promise.resolve(ldClient.intVariationDetail(flagKey, fallback));
EvaluationDetail<Integer> detailResult = ldClient.intVariationDetail(flagKey, fallback);
JsonObject jsonObject = gson.toJsonTree(detailResult).getAsJsonObject();
WritableMap detailMap = fromJsonObject(jsonObject);
promise.resolve(detailMap);
} catch (Exception e) {
promise.resolve(fallback);
}
Expand All @@ -595,7 +600,10 @@ public void floatVariationDetail(String flagKey, Promise promise) {
@ReactMethod
public void floatVariationDetailFallback(String flagKey, Float fallback, Promise promise) {
try {
promise.resolve(ldClient.floatVariationDetail(flagKey, fallback));
EvaluationDetail<Float> detailResult = ldClient.floatVariationDetail(flagKey, fallback);
JsonObject jsonObject = gson.toJsonTree(detailResult).getAsJsonObject();
WritableMap detailMap = fromJsonObject(jsonObject);
promise.resolve(detailMap);
} catch (Exception e) {
promise.resolve(fallback);
}
Expand All @@ -609,7 +617,10 @@ public void stringVariationDetail(String flagKey, Promise promise) {
@ReactMethod
public void stringVariationDetailFallback(String flagKey, String fallback, Promise promise) {
try {
promise.resolve(ldClient.stringVariationDetail(flagKey, fallback));
EvaluationDetail<String> detailResult = ldClient.stringVariationDetail(flagKey, fallback);
JsonObject jsonObject = gson.toJsonTree(detailResult).getAsJsonObject();
WritableMap detailMap = fromJsonObject(jsonObject);
promise.resolve(detailMap);
} catch (Exception e) {
promise.resolve(fallback);
}
Expand Down Expand Up @@ -762,7 +773,6 @@ public void allFlags(Promise promise) {
* <p>
* Separately typed methods are necessary at the React Native bridging layer requires that
* bridged method types disambiguate the value type.
* </p>
*
* @param eventName Name of the event to track
* @param data The Double data to attach to the tracking event
Expand All @@ -777,7 +787,6 @@ public void trackNumber(String eventName, Double data) {
* <p>
* Separately typed methods are necessary at the React Native bridging layer requires that
* bridged method types disambiguate the value type.
* </p>
*
* @param eventName Name of the event to track
* @param data The Boolean data to attach to the tracking event
Expand All @@ -792,7 +801,6 @@ public void trackBool(String eventName, Boolean data) {
* <p>
* Separately typed methods are necessary at the React Native bridging layer requires that
* bridged method types disambiguate the value type.
* </p>
*
* @param eventName Name of the event to track
* @param data The String data to attach to the tracking event
Expand All @@ -807,7 +815,6 @@ public void trackString(String eventName, String data) {
* <p>
* Separately typed methods are necessary at the React Native bridging layer requires that
* bridged method types disambiguate the value type.
* </p>
*
* @param eventName Name of the event to track
* @param data The Array data to attach to the tracking event
Expand All @@ -822,7 +829,6 @@ public void trackArray(String eventName, ReadableArray data) {
* <p>
* Separately typed methods are necessary at the React Native bridging layer requires that
* bridged method types disambiguate the value type.
* </p>
*
* @param eventName Name of the event to track
* @param data The Map(Object) data to attach to the tracking event
Expand Down Expand Up @@ -1027,7 +1033,7 @@ public void registerCurrentConnectionModeListener(String listenerId) {
@Override
public void onConnectionModeChanged(ConnectionInformation connectionInfo) {
WritableMap result = Arguments.createMap();
result.putString("connectionMode", new Gson().toJson(connectionInfo));
result.putString("connectionMode", gson.toJson(connectionInfo));

getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
Expand Down Expand Up @@ -1056,7 +1062,7 @@ public void registerAllFlagsListener(String listenerId) {
@Override
public void onChange(List<String> flagKeys) {
WritableMap result = Arguments.createMap();
result.putString("flagKeys", new Gson().toJson(flagKeys));
result.putString("flagKeys", gson.toJson(flagKeys));

getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
Expand All @@ -1081,7 +1087,6 @@ public void unregisterAllFlagsListener(String listenerId) {
* <p>
* This will recursively convert internal ReadableMaps and ReadableArrays into JsonObjects and
* JsonArrays.
* </p>
*
* @param readableMap A ReadableMap to be converted to a JsonObject
* @return A JsonObject containing the converted elements from the ReadableMap.
Expand Down Expand Up @@ -1128,7 +1133,6 @@ private static JsonObject toJsonObject(ReadableMap readableMap) {
* <p>
* This will recursively convert internal ReadableMaps and ReadableArrays into JsonObjects and
* JsonArrays.
* </p>
*
* @param readableArray A ReadableArray to be converted to a JsonArray
* @return A JsonArray containing the converted elements from the ReadableArray
Expand Down Expand Up @@ -1172,7 +1176,6 @@ private static JsonArray toJsonArray(ReadableArray readableArray) {
* <p>
* This will recursively convert internal JsonObjects and JsonArrays into WritableMaps and
* WritableArrays.
* </p>
*
* @param jsonArray A JsonArray to be converted into a WritableArray
* @return A WritableArray containing converted elements from the JsonArray
Expand Down Expand Up @@ -1209,7 +1212,6 @@ private static WritableArray fromJsonArray(JsonArray jsonArray) {
* <p>
* This will recursively convert internal JsonObjects and JsonArrays into WritableMaps and
* WritableArrays.
* </p>
*
* @param jsonObject A JsonObject to be converted into a WritableMap
* @return A WritableMap containing converted elements from the jsonObject
Expand Down Expand Up @@ -1265,7 +1267,6 @@ interface ConvertFromReadable<T> {
* Each type of config entry has a base ReadableType for checking that a ReadableMap contains an
* entry of the correct type, as well as an implementation of ConvertFromReadable for retrieving
* and converting a ReadableMap entry into a non base type for configuration processing.
* </p>
*/
enum ConfigEntryType implements ConvertFromReadable {
String(ReadableType.String) {
Expand Down
2 changes: 1 addition & 1 deletion ios/LaunchdarklyReactNativeClient.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Pod::Spec.new do |s|
s.swift_version = "5.0"

s.dependency "React"
s.dependency "LaunchDarkly", "4.3.2"
s.dependency "LaunchDarkly", "4.4.0"

end
Loading

0 comments on commit b94d706

Please sign in to comment.