Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[all] Use argscheck in accelerometer.js

  • Loading branch information...
commit 9ba65d4f42cddf0cdc1c1f1b624df201bde0ca18 1 parent bd3e925
@agrieve agrieve authored
Showing with 8 additions and 14 deletions.
  1. +7 −13 lib/common/plugin/accelerometer.js
  2. +1 −1  test/test.accelerometer.js
View
20 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 {
View
2  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", []);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.