@@ -9,31 +9,31 @@ 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 }
20-
20+
2121 override func constantsToExport( ) -> [ AnyHashable : Any ] {
2222 return [ " FLAG_PREFIX " : FLAG_PREFIX, " ALL_FLAGS_PREFIX " : ALL_FLAGS_PREFIX, " CONNECTION_MODE_PREFIX " : CONNECTION_MODE_PREFIX]
2323 }
24-
24+
2525 override static func requiresMainQueueSetup( ) -> Bool {
2626 return false
2727 }
28-
28+
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 getLDClient( environment: String ) -> LDClient ? {
3838 if let client = LDClient . get ( environment: environment) {
3939 return client
@@ -42,10 +42,10 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
4242 return nil
4343 }
4444 }
45-
45+
4646 private func internalConfigure( config: NSDictionary , user: NSDictionary , timeout: Int ? , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) {
4747 let config = configBuild ( config: config)
48-
48+
4949 if let config = config {
5050 if let timeoutUnwrapped = timeout {
5151 let startWaitSeconds : TimeInterval = Double ( timeoutUnwrapped)
@@ -63,7 +63,7 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
6363 }
6464 }
6565 }
66-
66+
6767 private func id< T> ( _ x: T ) -> T { x }
6868 private func millis( _ x: NSNumber ) -> TimeInterval { TimeInterval ( x. doubleValue / 1_000 ) }
6969 private func url( _ x: String ) -> URL { URL . init ( string: x) ! }
@@ -72,11 +72,11 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
7272 field = res
7373 }
7474 }
75-
75+
7676 private func configBuild( config: NSDictionary ) -> LDConfig ? {
7777 guard let mobileKey = config [ " mobileKey " ] as? String
7878 else { return nil }
79-
79+
8080 var ldConfig = LDConfig ( mobileKey: mobileKey)
8181 configField ( & ldConfig. baseUrl, config [ " pollUri " ] , url)
8282 configField ( & ldConfig. eventsUrl, config [ " eventsUri " ] , url)
@@ -101,28 +101,28 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
101101 configField ( & ldConfig. autoAliasingOptOut, config [ " autoAliasingOptOut " ] , id)
102102 configField ( & ldConfig. inlineUserInEvents, config [ " inlineUsersInEvents " ] , id)
103103 configField ( & ldConfig. privateUserAttributes, config [ " privateAttributeNames " ] , { ( x: [ String ] ) in x. map { UserAttribute . forName ( $0) } } )
104-
104+
105105 if let val = config [ " secondaryMobileKeys " ] as? [ String : String ] {
106106 try ! ldConfig. setSecondaryMobileKeys ( val)
107107 }
108-
108+
109109 if let c = config [ " application " ] as? [ String : String ] {
110110 var applicationInfo = ApplicationInfo ( )
111-
111+
112112 if let applicationId = c [ " id " ] {
113113 applicationInfo. applicationIdentifier ( applicationId)
114114 }
115-
115+
116116 if let applicationVersion = c [ " version " ] {
117117 applicationInfo. applicationVersion ( applicationVersion)
118118 }
119-
119+
120120 ldConfig. applicationInfo = applicationInfo
121121 }
122-
122+
123123 return ldConfig
124124 }
125-
125+
126126 private func userBuild( _ userDict: NSDictionary ) -> LDUser {
127127 var user = LDUser ( key: userDict [ " key " ] as? String )
128128 if let anon = userDict [ " anonymous " ] as? Bool {
@@ -141,7 +141,7 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
141141 user. custom = ( userDict [ " custom " ] as? [ String : Any ] ?? [ : ] ) . mapValues { LDValue . fromBridge ( $0) }
142142 return user
143143 }
144-
144+
145145 @objc func boolVariation( _ flagKey: String , defaultValue: ObjCBool , environment: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) {
146146 if let ldClient = getLDClient ( environment: environment) {
147147 resolve ( ldClient. boolVariation ( forKey: flagKey, defaultValue: defaultValue. boolValue) )
@@ -170,7 +170,6 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
170170 }
171171
172172 @objc func jsonVariation( _ flagKey: String , defaultValue: Any , environment: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) {
173- resolve ( getLDClient ( environment: environment) ? . jsonVariation ( forKey: flagKey, defaultValue: LDValue . fromBridge ( defaultValue) ) . toBridge ( ) )
174173 if let ldClient = getLDClient ( environment: environment) {
175174 resolve ( ldClient. jsonVariation ( forKey: flagKey, defaultValue: LDValue . fromBridge ( defaultValue) ) . toBridge ( ) )
176175 } else {
@@ -364,7 +363,7 @@ class LaunchdarklyReactNativeClient: RCTEventEmitter {
364363 getLDClient ( environment: environment) ? . stopObserving ( owner: owner)
365364 }
366365 }
367-
366+
368367 @objc func isInitialized( _ environment: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) {
369368 if LDClient . get ( ) == nil {
370369 reject ( ERROR_UNKNOWN, " SDK has not been configured " , nil )
@@ -399,7 +398,7 @@ extension LDValue {
399398 if let dictValue = value as? [ String : Any ] { return . object( dictValue. mapValues { fromBridge ( $0) } ) }
400399 return . null
401400 }
402-
401+
403402 func toBridge( ) -> Any {
404403 switch self {
405404 case . null: return NSNull ( )
0 commit comments