cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [9/9] js commit: [all] Use argscheck in accelerometer.js
Date Thu, 22 Nov 2012 20:47:47 GMT
[all] Use argscheck in accelerometer.js

https://issues.apache.org/jira/browse/CB-1892


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

Branch: refs/heads/master
Commit: 9ba65d4f42cddf0cdc1c1f1b624df201bde0ca18
Parents: bd3e925
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Nov 22 15:36:07 2012 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Nov 22 15:45:05 2012 -0500

----------------------------------------------------------------------
 lib/common/plugin/accelerometer.js |   20 +++++++-------------
 test/test.accelerometer.js         |    2 +-
 2 files changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/9ba65d4f/lib/common/plugin/accelerometer.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/accelerometer.js b/lib/common/plugin/accelerometer.js
index d52b6a9..da50487 100644
--- a/lib/common/plugin/accelerometer.js
+++ b/lib/common/plugin/accelerometer.js
@@ -23,7 +23,8 @@
  * This class provides access to device accelerometer data.
  * @constructor
  */
-var utils = require("cordova/utils"),
+var argscheck = require('cordova/argscheck'),
+    utils = require("cordova/utils"),
     exec = require("cordova/exec"),
     Acceleration = require('cordova/plugin/Acceleration');
 
@@ -87,10 +88,7 @@ var accelerometer = {
      * @param {AccelerationOptions} options The options for getting the accelerometer data
such as timeout. (OPTIONAL)
      */
     getCurrentAcceleration: function(successCallback, errorCallback, options) {
-        // successCallback required
-        if (typeof successCallback !== "function") {
-            throw "getCurrentAcceleration must be called with at least a success callback
function as first parameter.";
-        }
+        argscheck.checkArgs('fFO', 'accelerometer.getCurrentAcceleration', arguments);
 
         var p;
         var win = function(a) {
@@ -99,7 +97,7 @@ var accelerometer = {
         };
         var fail = function(e) {
             removeListeners(p);
-            errorCallback(e);
+            errorCallback && errorCallback(e);
         };
 
         p = createCallbackPair(win, fail);
@@ -119,20 +117,16 @@ var accelerometer = {
      * @return String                       The watch id that must be passed to #clearWatch
to stop watching.
      */
     watchAcceleration: function(successCallback, errorCallback, options) {
+        argscheck.checkArgs('fFO', 'accelerometer.watchAcceleration', arguments);
         // Default interval (10 sec)
         var frequency = (options && options.frequency && typeof options.frequency
== 'number') ? options.frequency : 10000;
 
-        // successCallback required
-        if (typeof successCallback !== "function") {
-            throw "watchAcceleration must be called with at least a success callback function
as first parameter.";
-        }
-
         // Keep reference to watch id, and report accel readings as often as defined in frequency
         var id = utils.createUUID();
 
         var p = createCallbackPair(function(){}, function(e) {
             removeListeners(p);
-            errorCallback(e);
+            errorCallback && errorCallback(e);
         });
         listeners.push(p);
 
@@ -148,7 +142,7 @@ var accelerometer = {
         if (running) {
             // If we're already running then immediately invoke the success callback
             // but only if we have retrieved a value, sample code does not check for null
...
-            if(accel) {
+            if (accel) {
                 successCallback(accel);
             }
         } else {

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/9ba65d4f/test/test.accelerometer.js
----------------------------------------------------------------------
diff --git a/test/test.accelerometer.js b/test/test.accelerometer.js
index b2e0d46..3b7d90e 100644
--- a/test/test.accelerometer.js
+++ b/test/test.accelerometer.js
@@ -63,7 +63,7 @@ describe("accelerometer", function () {
                 var success = function () {},
                     error = function () {};
 
-                accelerometer.getCurrentAcceleration(success, error, "options");
+                accelerometer.getCurrentAcceleration(success, error, {});
                 expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function),
"Accelerometer", "start", []);
             });
         });


Mime
View raw message