cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/2] ios commit: Remove some unnecessary argument checks in CDVNotification
Date Thu, 21 Mar 2013 03:08:40 GMT
Remove some unnecessary argument checks in CDVNotification

The JS ensures that all the params are present, and that they are not
nil.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/e9e67d0b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/e9e67d0b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/e9e67d0b

Branch: refs/heads/master
Commit: e9e67d0b976ca69b5374fd6bb67e052032fe66b0
Parents: 0b0b431
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Mar 20 23:07:34 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Mar 20 23:07:34 2013 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVNotification.m |   59 +++++++----------------------
 1 files changed, 14 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/e9e67d0b/CordovaLib/Classes/CDVNotification.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVNotification.m b/CordovaLib/Classes/CDVNotification.m
index b74eea0..821cb9f 100644
--- a/CordovaLib/Classes/CDVNotification.m
+++ b/CordovaLib/Classes/CDVNotification.m
@@ -61,19 +61,9 @@
 - (void)alert:(CDVInvokedUrlCommand*)command
 {
     NSString* callbackId = command.callbackId;
-    NSArray* arguments = command.arguments;
-    int argc = [arguments count];
-
-    NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
-    NSString* title = argc > 1 ? [arguments objectAtIndex:1] : nil;
-    NSString* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
-
-    if (!title) {
-        title = NSLocalizedString(@"Alert", @"Alert");
-    }
-    if (!buttons) {
-        buttons = NSLocalizedString(@"OK", @"OK");
-    }
+    NSString* message = [command argumentAtIndex:0];
+    NSString* title = [command argumentAtIndex:1];
+    NSString* buttons = [command argumentAtIndex:2];
 
     [self showDialogWithMessage:message title:title buttons:@[buttons] callbackId:callbackId
dialogType:DIALOG_TYPE_ALERT];
 }
@@ -81,19 +71,9 @@
 - (void)confirm:(CDVInvokedUrlCommand*)command
 {
     NSString* callbackId = command.callbackId;
-    NSArray* arguments = command.arguments;
-    int argc = [arguments count];
-
-    NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
-    NSString* title = argc > 1 ? [arguments objectAtIndex:1] : nil;
-    NSArray* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
-
-    if (!title) {
-        title = NSLocalizedString(@"Confirm", @"Confirm");
-    }
-    if (!buttons) {
-        buttons = @[NSLocalizedString(@"OK", @"OK"), NSLocalizedString(@"Cancel", @"Cancel")];
-    }
+    NSString* message = [command argumentAtIndex:0];
+    NSString* title = [command argumentAtIndex:1];
+    NSArray* buttons = [command argumentAtIndex:2];
 
     [self showDialogWithMessage:message title:title buttons:buttons callbackId:callbackId
dialogType:DIALOG_TYPE_ALERT];
 }
@@ -101,22 +81,10 @@
 - (void)prompt:(CDVInvokedUrlCommand*)command
 {
     NSString* callbackId = command.callbackId;
-    NSArray* arguments = command.arguments;
-    int argc = [arguments count];
-
-    NSString* message = argc > 0 ? [arguments objectAtIndex:0] : nil;
-    NSString* title = argc > 1 ? [arguments objectAtIndex:1] : nil;
-    NSArray* buttons = argc > 2 ? [arguments objectAtIndex:2] : nil;
+    NSString* message = [command argumentAtIndex:0];
+    NSString* title = [command argumentAtIndex:1];
+    NSArray* buttons = [command argumentAtIndex:2];
 
-    if (!message) {
-        title = NSLocalizedString(@"Prompt message", @"Prompt message");
-    }
-    if (!title) {
-        title = NSLocalizedString(@"Prompt", @"Prompt");
-    }
-    if (!buttons) {
-        buttons = @[NSLocalizedString(@"OK", @"OK"), NSLocalizedString(@"Cancel", @"Cancel")];
-    }
     [self showDialogWithMessage:message title:title buttons:buttons callbackId:callbackId
dialogType:DIALOG_TYPE_PROMPT];
 }
 
@@ -131,13 +99,14 @@
     // Determine what gets returned to JS based on the alert view type.
     if (alertView.alertViewStyle == UIAlertViewStyleDefault) {
         // For alert and confirm, return button index as int back to JS.
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:++buttonIndex];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:buttonIndex
+ 1];
     } else {
         // For prompt, return button index and input text back to JS.
         NSString* value0 = [[alertView textFieldAtIndex:0] text];
-        NSMutableDictionary* info = [NSMutableDictionary dictionaryWithCapacity:3];
-        [info setValue:[NSNumber numberWithInt:++buttonIndex] forKey:@"buttonIndex"];
-        [info setValue:value0 ? value0:[NSNull null] forKey:@"input1"];
+        NSDictionary* info = @{
+            @"buttonIndex":@(buttonIndex + 1),
+            @"input1":(value0 ? value0 : [NSNull null])
+        };
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info];
     }
     [self.commandDelegate sendPluginResult:result callbackId:cdvAlertView.callbackId];


Mime
View raw message