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

Commit f9ee647

Browse files
authored
Merge pull request #134 from launchdarkly/yus/sc-185314/format-swift-code
[sc-185314] Prettify swift code and split modd file
2 parents 50bc73e + 70d1983 commit f9ee647

File tree

4 files changed

+81
-82
lines changed

4 files changed

+81
-82
lines changed

README.md

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,56 @@
1-
LaunchDarkly Client-Side SDK for React Native
2-
===========================
1+
# LaunchDarkly Client-Side SDK for React Native
32

43
[![NPM](https://img.shields.io/npm/v/launchdarkly-react-native-client-sdk.svg)](https://www.npmjs.com/package/launchdarkly-react-native-client-sdk)
54
[![CircleCI](https://circleci.com/gh/launchdarkly/react-native-client-sdk.svg?style=shield)](https://circleci.com/gh/launchdarkly/react-native-client-sdk)
65
[![Documentation](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://launchdarkly.github.io/react-native-client-sdk)
76

8-
LaunchDarkly overview
9-
-------------------------
7+
## LaunchDarkly overview
8+
109
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
1110

1211
[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
1312

14-
Supported versions
15-
-------------------------
13+
## Supported versions
1614

1715
This SDK is currently compatible with React Native versions `>=0.64 <0.71`, the minimum iOS deployment target is `10.0`, and the minimum Android SDK version is `21`. Builds are tested with XCode 12.5+. Please look at the CircleCI test build to see which combination of React Native and XCode works together.
1816

1917
For React Native `0.63.x` support, use the latest [`5.1.x` release](https://github.com/launchdarkly/react-native-client-sdk/releases/tag/5.1.1).
2018

21-
Getting started
22-
---------------
19+
## Getting started
2320

2421
Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/client-side/react/react-native#getting-started) for instructions on getting started with using the SDK.
2522

26-
Learn more
27-
-----------
23+
## Learn more
2824

2925
Check out our [documentation](https://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/client-side/react/react-native).
3026

31-
Testing
32-
-------
27+
## Testing
3328

3429
We run integration tests for all our SDKs using a centralized test harness. This approach gives us the ability to test for consistency across SDKs, as well as test networking behavior in a long-running application. These tests cover each method in the SDK, and verify that event sending, flag evaluation, stream reconnection, and other aspects of the SDK all behave correctly.
3530

36-
Contributing
37-
------------
31+
## Contributing
3832

3933
We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK.
4034

41-
About LaunchDarkly
42-
-----------
43-
44-
* LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
45-
* Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
46-
* Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
47-
* Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
48-
* Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
49-
* LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
50-
* Explore LaunchDarkly
51-
* [launchdarkly.com](https://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
52-
* [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
53-
* [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
54-
* [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
55-
56-
Developing this SDK
57-
-----------
58-
59-
* Run `npx react-native doctor` in both the root and ManualTestApp directories and make sure everything is green
60-
* If watchman fails, you can try installing it manually `brew reinstall watchman`
61-
* Make sure you have [modd](https://github.com/cortesi/modd#install) installed so native code changes are hot reloaded
62-
* Run `modd`
35+
## About LaunchDarkly
36+
37+
- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
38+
- Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
39+
- Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
40+
- Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
41+
- Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
42+
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
43+
- Explore LaunchDarkly
44+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
45+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
46+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
47+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
48+
49+
## Developing this SDK
50+
51+
- Run `npx react-native doctor` in both the root and ManualTestApp directories and make sure everything is green
52+
- If watchman fails, you can try installing it manually `brew reinstall watchman`
53+
- Make sure you have [modd](https://github.com/cortesi/modd#install) installed so native code changes are hot reloaded
54+
55+
* For ios run `modd -f modd-ios.conf`
56+
* For android run `modd -f modd-android.conf`

ios/LaunchdarklyReactNativeClient.swift

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
99
private let ERROR_INIT = "E_INITIALIZE"
1010
private let ERROR_IDENTIFY = "E_IDENTIFY"
1111
private let ERROR_UNKNOWN = "E_UNKNOWN"
12-
12+
1313
private var flagListenerOwners: [String: ObserverOwner] = [:]
1414
private var allFlagsListenerOwners: [String: ObserverOwner] = [:]
1515
private var connectionModeListenerOwners: [String: ObserverOwner] = [:]
16-
16+
1717
override func supportedEvents() -> [String]! {
1818
return [FLAG_PREFIX, ALL_FLAGS_PREFIX, CONNECTION_MODE_PREFIX]
1919
}
@@ -29,14 +29,14 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
2929
@objc func configure(_ config: NSDictionary, user: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
3030
internalConfigure(config: config, user: user, timeout: nil, resolve: resolve, reject: reject)
3131
}
32-
32+
3333
@objc func configureWithTimeout(_ config: NSDictionary, user: NSDictionary, timeout: Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
3434
internalConfigure(config: config, user: user, timeout: timeout, resolve: resolve, reject: reject)
3535
}
36-
36+
3737
private func internalConfigure(config: NSDictionary, user: NSDictionary, timeout: Int?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
3838
let config = configBuild(config: config)
39-
39+
4040
if let config = config {
4141
if let timeoutUnwrapped = timeout {
4242
let startWaitSeconds: TimeInterval = Double(timeoutUnwrapped)
@@ -54,7 +54,7 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
5454
}
5555
}
5656
}
57-
57+
5858
private func id<T>(_ x: T) -> T { x }
5959
private func millis(_ x: NSNumber) -> TimeInterval { TimeInterval(x.doubleValue / 1_000) }
6060
private func url(_ x: String) -> URL { URL.init(string: x)! }
@@ -67,7 +67,7 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
6767
private func configBuild(config: NSDictionary) -> LDConfig? {
6868
guard let mobileKey = config["mobileKey"] as? String
6969
else { return nil }
70-
70+
7171
var ldConfig = LDConfig(mobileKey: mobileKey)
7272
configField(&ldConfig.baseUrl, config["pollUri"], url)
7373
configField(&ldConfig.eventsUrl, config["eventsUri"], url)
@@ -92,14 +92,14 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
9292
configField(&ldConfig.autoAliasingOptOut, config["autoAliasingOptOut"], id)
9393
configField(&ldConfig.inlineUserInEvents, config["inlineUsersInEvents"], id)
9494
configField(&ldConfig.privateUserAttributes, config["privateAttributeNames"], { (x: [String]) in x.map { UserAttribute.forName($0) }})
95-
95+
9696
if let val = config["secondaryMobileKeys"] as? [String: String] {
9797
try! ldConfig.setSecondaryMobileKeys(val)
9898
}
99-
99+
100100
return ldConfig
101101
}
102-
102+
103103
private func userBuild(_ userDict: NSDictionary) -> LDUser {
104104
var user = LDUser(key: userDict["key"] as? String)
105105
if let anon = userDict["anonymous"] as? Bool {
@@ -118,97 +118,97 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
118118
user.custom = (userDict["custom"] as? [String: Any] ?? [:]).mapValues { LDValue.fromBridge($0) }
119119
return user
120120
}
121-
121+
122122
@objc func boolVariation(_ flagKey: String, defaultValue: ObjCBool, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
123123
resolve(LDClient.get(environment: environment)!.boolVariation(forKey: flagKey, defaultValue: defaultValue.boolValue))
124124
}
125-
125+
126126
@objc func numberVariation(_ flagKey: String, defaultValue: Double, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
127127
resolve(LDClient.get(environment: environment)!.doubleVariation(forKey: flagKey, defaultValue: defaultValue))
128128
}
129-
129+
130130
@objc func stringVariation(_ flagKey: String, defaultValue: String, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
131131
resolve(LDClient.get(environment: environment)!.stringVariation(forKey: flagKey, defaultValue: defaultValue))
132132
}
133-
133+
134134
@objc func jsonVariation(_ flagKey: String, defaultValue: Any, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
135135
resolve(LDClient.get(environment: environment)!.jsonVariation(forKey: flagKey, defaultValue: LDValue.fromBridge(defaultValue)).toBridge())
136136
}
137-
137+
138138
@objc func boolVariationDetail(_ flagKey: String, defaultValue: ObjCBool, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
139139
let detail = LDClient.get(environment: environment)!.boolVariationDetail(forKey: flagKey, defaultValue: defaultValue.boolValue)
140140
resolve(bridgeDetail(detail, id))
141141
}
142-
142+
143143
@objc func numberVariationDetail(_ flagKey: String, defaultValue: Double, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
144144
let detail = LDClient.get(environment: environment)!.doubleVariationDetail(forKey: flagKey, defaultValue: defaultValue)
145145
resolve(bridgeDetail(detail, id))
146146
}
147-
147+
148148
@objc func stringVariationDetail(_ flagKey: String, defaultValue: String, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
149149
let detail = LDClient.get(environment: environment)!.stringVariationDetail(forKey: flagKey, defaultValue: defaultValue)
150150
resolve(bridgeDetail(detail, id))
151151
}
152-
152+
153153
@objc func jsonVariationDetail(_ flagKey: String, defaultValue: Any, environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
154154
let detail = LDClient.get(environment: environment)!.jsonVariationDetail(forKey: flagKey, defaultValue: LDValue.fromBridge(defaultValue))
155155
resolve(bridgeDetail(detail, { $0.toBridge() }))
156156
}
157-
157+
158158
private func bridgeDetail<T>(_ detail: LDEvaluationDetail<T>, _ converter: ((T) -> Any)) -> NSDictionary {
159159
[ "value": converter(detail.value)
160-
, "variationIndex": (detail.variationIndex as Any)
161-
, "reason": ((detail.reason?.mapValues { $0.toBridge() }) as Any)
160+
, "variationIndex": (detail.variationIndex as Any)
161+
, "reason": ((detail.reason?.mapValues { $0.toBridge() }) as Any)
162162
]
163163
}
164-
164+
165165
@objc func trackData(_ eventName: String, data: Any, environment: String) {
166166
LDClient.get(environment: environment)!.track(key: eventName, data: LDValue.fromBridge(data))
167167
}
168-
168+
169169
@objc func trackMetricValue(_ eventName: String, data: Any, metricValue: NSNumber, environment: String) {
170170
LDClient.get(environment: environment)!.track(key: eventName, data: LDValue.fromBridge(data), metricValue: Double(truncating: metricValue))
171171
}
172-
172+
173173
@objc func setOffline(_ resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
174174
LDClient.get()?.setOnline(false) {
175175
resolve(true)
176176
}
177177
}
178-
178+
179179
@objc func isOffline(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
180180
resolve(!(LDClient.get()?.isOnline ?? false))
181181
}
182-
182+
183183
@objc func setOnline(_ resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
184184
LDClient.get()?.setOnline(true) {
185185
resolve(true)
186186
}
187187
}
188-
188+
189189
@objc func flush() {
190190
LDClient.get()?.flush()
191191
}
192-
192+
193193
@objc func close(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
194194
LDClient.get()?.close()
195195
resolve(true)
196196
}
197-
197+
198198
@objc func identify(_ options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
199199
LDClient.get()?.identify(user: userBuild(options)) {
200200
resolve(nil)
201201
}
202202
}
203-
203+
204204
@objc func alias(_ environment: String, user: NSDictionary, previousUser: NSDictionary) {
205205
LDClient.get(environment: environment)!.alias(context: userBuild(user), previousContext: userBuild(previousUser))
206206
}
207-
207+
208208
@objc func allFlags(_ environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
209209
resolve(LDClient.get(environment: environment)!.allFlags?.mapValues { $0.toBridge() } ?? [:] as NSDictionary)
210210
}
211-
211+
212212
@objc func getConnectionMode(_ environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
213213
let connectionInformation = LDClient.get(environment: environment)!.getConnectionInformation()
214214
var connectionMode: String
@@ -224,16 +224,16 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
224224
}
225225
resolve(connectionMode)
226226
}
227-
227+
228228
// lastKnownFlagValidity is nil if either no connection has ever been successfully made or if the SDK has an active streaming connection. It will have a value if 1) in polling mode and at least one poll has completed successfully, or 2) if in streaming mode whenever the streaming connection closes.
229229
@objc func getLastSuccessfulConnection(_ environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
230230
resolve(LDClient.get(environment: environment)!.getConnectionInformation().lastKnownFlagValidity ?? 0)
231231
}
232-
232+
233233
@objc func getLastFailedConnection(_ environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
234234
resolve(LDClient.get(environment: environment)!.getConnectionInformation().lastFailedConnection ?? 0)
235235
}
236-
236+
237237
@objc func getLastFailure(_ environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
238238
let connectionInformation = LDClient.get(environment: environment)!.getConnectionInformation()
239239
var failureReason: String
@@ -249,11 +249,11 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
249249
}
250250
resolve(failureReason)
251251
}
252-
252+
253253
private func envConcat(environment: String, identifier: String) -> String {
254254
return environment + ";" + identifier
255255
}
256-
256+
257257
@objc func registerFeatureFlagListener(_ flagKey: String, environment: String) {
258258
let multiListenerId = envConcat(environment: environment, identifier: flagKey)
259259
let owner = ObserverOwner()
@@ -264,14 +264,14 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
264264
}
265265
}
266266
}
267-
267+
268268
@objc func unregisterFeatureFlagListener(_ flagKey: String, environment: String) {
269269
let multiListenerId = envConcat(environment: environment, identifier: flagKey)
270270
if let owner = flagListenerOwners.removeValue(forKey: multiListenerId) {
271271
LDClient.get(environment: environment)!.stopObserving(owner: owner)
272272
}
273273
}
274-
274+
275275
@objc func registerCurrentConnectionModeListener(_ listenerId: String, environment: String) {
276276
let multiListenerId = envConcat(environment: environment, identifier: listenerId)
277277
let owner = ObserverOwner()
@@ -282,14 +282,14 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
282282
}
283283
}
284284
}
285-
285+
286286
@objc func unregisterCurrentConnectionModeListener(_ listenerId: String, environment: String) {
287287
let multiListenerId = envConcat(environment: environment, identifier: listenerId)
288288
if let owner = connectionModeListenerOwners.removeValue(forKey: multiListenerId) {
289289
LDClient.get(environment: environment)!.stopObserving(owner: owner)
290290
}
291291
}
292-
292+
293293
@objc func registerAllFlagsListener(_ listenerId: String, environment: String) {
294294
let multiListenerId = envConcat(environment: environment, identifier: listenerId)
295295
let owner = ObserverOwner()
@@ -300,14 +300,14 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
300300
}
301301
}
302302
}
303-
303+
304304
@objc func unregisterAllFlagsListener(_ listenerId: String, environment: String) {
305305
let multiListenerId = envConcat(environment: environment, identifier: listenerId)
306306
if let owner = allFlagsListenerOwners.removeValue(forKey: multiListenerId) {
307307
LDClient.get(environment: environment)!.stopObserving(owner: owner)
308308
}
309309
}
310-
310+
311311
@objc func isInitialized(_ environment: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
312312
if LDClient.get() == nil {
313313
reject(ERROR_UNKNOWN, "SDK has not been configured", nil)
@@ -342,7 +342,7 @@ extension LDValue {
342342
if let dictValue = value as? [String: Any] { return .object(dictValue.mapValues { fromBridge($0) }) }
343343
return .null
344344
}
345-
345+
346346
func toBridge() -> Any {
347347
switch self {
348348
case .null: return NSNull()

modd-android.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
android/** package.json tsconfig.json {
2+
prep: yarn
3+
prep: yarn link-dev
4+
prep: yarn --cwd ManualTestApp android
5+
}

0 commit comments

Comments
 (0)