Skip to content

Commit 63d31ad

Browse files
gkalpakpetebacondarwin
authored andcommitted
refactor($resource): use local references of Angular helpers
1 parent db118df commit 63d31ad

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/ngResource/resource.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,10 @@ angular.module('ngResource', ['ng']).
519519
forEach = angular.forEach,
520520
extend = angular.extend,
521521
copy = angular.copy,
522-
isFunction = angular.isFunction;
522+
isArray = angular.isArray,
523+
isDefined = angular.isDefined,
524+
isFunction = angular.isFunction,
525+
isNumber = angular.isNumber;
523526

524527
/**
525528
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
@@ -595,7 +598,7 @@ angular.module('ngResource', ['ng']).
595598
params = params || {};
596599
forEach(self.urlParams, function(paramInfo, urlParam) {
597600
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
598-
if (angular.isDefined(val) && val !== null) {
601+
if (isDefined(val) && val !== null) {
599602
if (paramInfo.isQueryParamValue) {
600603
encodedVal = encodeUriQuery(val, true);
601604
} else {
@@ -673,11 +676,11 @@ angular.module('ngResource', ['ng']).
673676
forEach(actions, function(action, name) {
674677
var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
675678
var numericTimeout = action.timeout;
676-
var cancellable = angular.isDefined(action.cancellable) ? action.cancellable :
677-
(options && angular.isDefined(options.cancellable)) ? options.cancellable :
679+
var cancellable = isDefined(action.cancellable) ? action.cancellable :
680+
(options && isDefined(options.cancellable)) ? options.cancellable :
678681
provider.defaults.cancellable;
679682

680-
if (numericTimeout && !angular.isNumber(numericTimeout)) {
683+
if (numericTimeout && !isNumber(numericTimeout)) {
681684
$log.debug('ngResource:\n' +
682685
' Only numeric values are allowed as `timeout`.\n' +
683686
' Promises are not supported in $resource, because the same value would ' +
@@ -768,11 +771,11 @@ angular.module('ngResource', ['ng']).
768771

769772
if (data) {
770773
// Need to convert action.isArray to boolean in case it is undefined
771-
if (angular.isArray(data) !== (!!action.isArray)) {
774+
if (isArray(data) !== (!!action.isArray)) {
772775
throw $resourceMinErr('badcfg',
773776
'Error in resource configuration for action `{0}`. Expected response to ' +
774777
'contain an {1} but got an {2} (Request: {3} {4})', name, action.isArray ? 'array' : 'object',
775-
angular.isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url);
778+
isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url);
776779
}
777780
if (action.isArray) {
778781
value.length = 0;
@@ -803,7 +806,7 @@ angular.module('ngResource', ['ng']).
803806
promise['finally'](function() {
804807
value.$resolved = true;
805808
if (!isInstanceCall && cancellable) {
806-
value.$cancelRequest = angular.noop;
809+
value.$cancelRequest = noop;
807810
$timeout.cancel(numericTimeoutPromise);
808811
timeoutDeferred = numericTimeoutPromise = httpConfig.timeout = null;
809812
}

0 commit comments

Comments
 (0)