Support iOS FlipperConnection send with array parameters

Summary: Achieving API parity with C++ and Android.

Reviewed By: lblasa

Differential Revision: D31921830

fbshipit-source-id: 873901107fc3c53166fa7bbaaff65ebdb0e53c2a
This commit is contained in:
Edward Pastuszenski
2021-10-28 14:57:30 -07:00
committed by Facebook GitHub Bot
parent 4a4cc21d89
commit 64df212cd3
4 changed files with 34 additions and 8 deletions

View File

@@ -25,12 +25,20 @@
#pragma mark - SonarConnection #pragma mark - SonarConnection
- (void)send:(NSString*)method withParams:(NSDictionary*)params { - (void)sendInternal:(NSString*)method withParams:(id)params {
conn_->send( conn_->send(
[method UTF8String], [method UTF8String],
facebook::cxxutils::convertIdToFollyDynamic(params, true)); facebook::cxxutils::convertIdToFollyDynamic(params, true));
} }
- (void)send:(NSString*)method withParams:(NSDictionary*)params {
[self sendInternal:method withParams:params];
}
- (void)send:(NSString*)method withArrayParams:(NSArray*)params {
[self sendInternal:method withParams:params];
}
- (void)receive:(NSString*)method withBlock:(SonarReceiver)receiver { - (void)receive:(NSString*)method withBlock:(SonarReceiver)receiver {
const auto lambda = const auto lambda =
[receiver]( [receiver](

View File

@@ -23,6 +23,11 @@ Invoke a method on the Sonar desktop plugin with with a matching identifier.
*/ */
- (void)send:(NSString*)method withParams:(NSDictionary*)params; - (void)send:(NSString*)method withParams:(NSDictionary*)params;
/**
Invoke a method on the Sonar desktop plugin with with a matching identifier.
*/
- (void)send:(NSString*)method withArrayParams:(NSArray*)params;
/** /**
Register a receiver to be notified of incoming calls of the given method from Register a receiver to be notified of incoming calls of the given method from
the Sonar desktop plugin with a matching identifier. the Sonar desktop plugin with a matching identifier.

View File

@@ -16,5 +16,7 @@
NSDictionary<NSString*, SonarReceiver>* receivers; NSDictionary<NSString*, SonarReceiver>* receivers;
@property(nonatomic, readonly) @property(nonatomic, readonly)
NSDictionary<NSString*, NSArray<NSDictionary*>*>* sent; NSDictionary<NSString*, NSArray<NSDictionary*>*>* sent;
@property(nonatomic, readonly)
NSDictionary<NSString*, NSArray<NSArray*>*>* sentWithArray;
@end @end

View File

@@ -14,23 +14,34 @@
_connected = YES; _connected = YES;
_receivers = @{}; _receivers = @{};
_sent = @{}; _sent = @{};
_sentWithArray = @{};
} }
return self; return self;
} }
- (void)send:(NSString*)method withParams:(NSDictionary*)params { - (void)sendInternal:(NSString*)method
withParams:(id)params
loggedTo:(NSDictionary* __strong*)sentLog {
if (_connected) { if (_connected) {
NSMutableDictionary* newSent = [NSMutableDictionary new]; NSMutableDictionary* newSentLog = [NSMutableDictionary new];
[newSent addEntriesFromDictionary:_sent]; [newSentLog addEntriesFromDictionary:*sentLog];
if (newSent[method]) { if (newSentLog[method]) {
newSent[method] = [_sent[method] arrayByAddingObject:params]; newSentLog[method] = [(*sentLog)[method] arrayByAddingObject:params];
} else { } else {
newSent[method] = @[ params ]; newSentLog[method] = @[ params ];
} }
_sent = newSent; *sentLog = newSentLog;
} }
} }
- (void)send:(NSString*)method withParams:(NSDictionary*)params {
[self sendInternal:method withParams:params loggedTo:&_sent];
}
- (void)send:(NSString*)method withArrayParams:(NSArray*)params {
[self sendInternal:method withParams:params loggedTo:&_sentWithArray];
}
- (void)receive:(NSString*)method withBlock:(SonarReceiver)receiver { - (void)receive:(NSString*)method withBlock:(SonarReceiver)receiver {
if (_connected) { if (_connected) {
NSMutableDictionary* newReceivers = [NSMutableDictionary new]; NSMutableDictionary* newReceivers = [NSMutableDictionary new];