Skip to content

Commit

Permalink
making all block scoped variables constant and the blocks themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
tiholic committed Aug 3, 2020
1 parent 835bbfd commit d2614d4
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions ios/Classes/AblyFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ -(void)registerWithCompletionHandler:(FlutterResult)completionHandler;

NS_ASSUME_NONNULL_END

static FlutterHandler _getPlatformVersion = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _getPlatformVersion = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
result([@"iOS (UIKit) " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
};

static FlutterHandler _getVersion = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _getVersion = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
result([@"CocoaPod " stringByAppendingString:[ARTDefault libraryVersion]]);
};

static FlutterHandler _register = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _register = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
[plugin registerWithCompletionHandler:result];
};

static FlutterHandler _createRestWithOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _createRestWithOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
result([ably createRestWithOptions:message.message]);
};

static FlutterHandler _publishRestMessage = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _publishRestMessage = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
AblyFlutterMessage *const messageData = message.message;
NSMutableDictionary<NSString *, NSObject *>* _dataMap = messageData.message;
NSString *channelName = (NSString*)[_dataMap objectForKey:@"channel"];
NSMutableDictionary<NSString *, NSObject *> *const _dataMap = messageData.message;
NSString *const channelName = (NSString*)[_dataMap objectForKey:@"channel"];
NSString *const eventName = (NSString*)[_dataMap objectForKey:@"name"];
NSObject *const eventData = (NSString*)[_dataMap objectForKey:@"message"];
ARTRest *client = [ably getRest:messageData.handle];
ARTRestChannel *channel = [client.channels get:channelName];
ARTRest *const client = [ably getRest:messageData.handle];
ARTRestChannel *const channel = [client.channels get:channelName];

[channel publish:eventName data:eventData callback:^(ARTErrorInfo *_Nullable error){
if(error){
Expand All @@ -71,40 +71,39 @@ -(void)registerWithCompletionHandler:(FlutterResult)completionHandler;
}];
};

static FlutterHandler _createRealtimeWithOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _createRealtimeWithOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
result([ably createRealtimeWithOptions:message.message]);
};

static FlutterHandler _connectRealtime = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _connectRealtime = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
NSNumber *const handle = message.message;
[[ably realtimeWithHandle:handle] connect];
result(nil);
};

static FlutterHandler _closeRealtime = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _closeRealtime = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
NSNumber *const handle = message.message;
[[ably realtimeWithHandle:handle] close];
result(nil);
};

static FlutterHandler _attachRealtimeChannel = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _attachRealtimeChannel = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
AblyFlutterMessage *const data = message.message;
NSNumber *const realtimeHandle = data.handle;
ARTRealtime* realtimeWithHandle = [ably realtimeWithHandle: realtimeHandle];
ARTRealtime *const realtimeWithHandle = [ably realtimeWithHandle: realtimeHandle];

NSDictionary *const realtimePayload = data.message;
NSString *channelName = (NSString*)[realtimePayload objectForKey:@"channel"];
ARTChannelOptions *channelOptions = (ARTChannelOptions*)[realtimePayload objectForKey:@"options"];
ARTRealtimeChannel *channel;
channel = [realtimeWithHandle.channels get:channelName options:channelOptions];
NSString *const channelName = (NSString*)[realtimePayload objectForKey:@"channel"];
ARTChannelOptions *const channelOptions = (ARTChannelOptions*)[realtimePayload objectForKey:@"options"];
ARTRealtimeChannel *const channel = [realtimeWithHandle.channels get:channelName options:channelOptions];
[channel attach:^(ARTErrorInfo *_Nullable error){
if(error){
result([
Expand All @@ -119,18 +118,17 @@ -(void)registerWithCompletionHandler:(FlutterResult)completionHandler;
}];
};

static FlutterHandler _detachRealtimeChannel = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _detachRealtimeChannel = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const message = call.arguments;
AblyFlutter *const ably = [plugin ably];
AblyFlutterMessage *const data = message.message;
NSNumber *const realtimeHandle = data.handle;
ARTRealtime* realtimeWithHandle = [ably realtimeWithHandle: realtimeHandle];
ARTRealtime *const realtimeWithHandle = [ably realtimeWithHandle: realtimeHandle];

NSDictionary *const realtimePayload = data.message;
NSString *channelName = (NSString*)[realtimePayload objectForKey:@"channel"];
ARTChannelOptions *channelOptions = (ARTChannelOptions*)[realtimePayload objectForKey:@"options"];
ARTRealtimeChannel *channel;
channel = [realtimeWithHandle.channels get:channelName options:channelOptions];
NSString *const channelName = (NSString*)[realtimePayload objectForKey:@"channel"];
ARTChannelOptions *const channelOptions = (ARTChannelOptions*)[realtimePayload objectForKey:@"options"];
ARTRealtimeChannel *const channel = [realtimeWithHandle.channels get:channelName options:channelOptions];
[channel detach:^(ARTErrorInfo *_Nullable error){
if(error){
result([
Expand All @@ -145,7 +143,7 @@ -(void)registerWithCompletionHandler:(FlutterResult)completionHandler;
}];
};

static FlutterHandler _setRealtimeChannelOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
static const FlutterHandler _setRealtimeChannelOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
// cocoa library doesn't support setOptions yet!
result(nil);
};
Expand Down

0 comments on commit d2614d4

Please sign in to comment.