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:
committed by
Facebook GitHub Bot
parent
4a4cc21d89
commit
64df212cd3
@@ -25,12 +25,20 @@
|
||||
|
||||
#pragma mark - SonarConnection
|
||||
|
||||
- (void)send:(NSString*)method withParams:(NSDictionary*)params {
|
||||
- (void)sendInternal:(NSString*)method withParams:(id)params {
|
||||
conn_->send(
|
||||
[method UTF8String],
|
||||
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 {
|
||||
const auto lambda =
|
||||
[receiver](
|
||||
|
||||
@@ -23,6 +23,11 @@ Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
||||
*/
|
||||
- (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
|
||||
the Sonar desktop plugin with a matching identifier.
|
||||
|
||||
@@ -16,5 +16,7 @@
|
||||
NSDictionary<NSString*, SonarReceiver>* receivers;
|
||||
@property(nonatomic, readonly)
|
||||
NSDictionary<NSString*, NSArray<NSDictionary*>*>* sent;
|
||||
@property(nonatomic, readonly)
|
||||
NSDictionary<NSString*, NSArray<NSArray*>*>* sentWithArray;
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,23 +14,34 @@
|
||||
_connected = YES;
|
||||
_receivers = @{};
|
||||
_sent = @{};
|
||||
_sentWithArray = @{};
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)send:(NSString*)method withParams:(NSDictionary*)params {
|
||||
- (void)sendInternal:(NSString*)method
|
||||
withParams:(id)params
|
||||
loggedTo:(NSDictionary* __strong*)sentLog {
|
||||
if (_connected) {
|
||||
NSMutableDictionary* newSent = [NSMutableDictionary new];
|
||||
[newSent addEntriesFromDictionary:_sent];
|
||||
if (newSent[method]) {
|
||||
newSent[method] = [_sent[method] arrayByAddingObject:params];
|
||||
NSMutableDictionary* newSentLog = [NSMutableDictionary new];
|
||||
[newSentLog addEntriesFromDictionary:*sentLog];
|
||||
if (newSentLog[method]) {
|
||||
newSentLog[method] = [(*sentLog)[method] arrayByAddingObject:params];
|
||||
} 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 {
|
||||
if (_connected) {
|
||||
NSMutableDictionary* newReceivers = [NSMutableDictionary new];
|
||||
|
||||
Reference in New Issue
Block a user