refactor($resource): use local references of Angular helpers

This commit is contained in:
Georgios Kalpakas
2016-09-19 21:55:31 +03:00
parent 6eb4ffc085
commit bf61c1471d
+10 -7
View File
@@ -522,7 +522,10 @@ angular.module('ngResource', ['ng']).
forEach = angular.forEach,
extend = angular.extend,
copy = angular.copy,
isArray = angular.isArray,
isDefined = angular.isDefined,
isFunction = angular.isFunction,
isNumber = angular.isNumber,
encodeUriQuery = angular.$$encodeUriQuery,
encodeUriSegment = angular.$$encodeUriSegment;
@@ -561,7 +564,7 @@ angular.module('ngResource', ['ng']).
params = params || {};
forEach(self.urlParams, function(paramInfo, urlParam) {
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
if (angular.isDefined(val) && val !== null) {
if (isDefined(val) && val !== null) {
if (paramInfo.isQueryParamValue) {
encodedVal = encodeUriQuery(val, true);
} else {
@@ -639,11 +642,11 @@ angular.module('ngResource', ['ng']).
forEach(actions, function(action, name) {
var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
var numericTimeout = action.timeout;
var cancellable = angular.isDefined(action.cancellable) ? action.cancellable :
(options && angular.isDefined(options.cancellable)) ? options.cancellable :
var cancellable = isDefined(action.cancellable) ? action.cancellable :
(options && isDefined(options.cancellable)) ? options.cancellable :
provider.defaults.cancellable;
if (numericTimeout && !angular.isNumber(numericTimeout)) {
if (numericTimeout && !isNumber(numericTimeout)) {
$log.debug('ngResource:\n' +
' Only numeric values are allowed as `timeout`.\n' +
' Promises are not supported in $resource, because the same value would ' +
@@ -736,11 +739,11 @@ angular.module('ngResource', ['ng']).
if (data) {
// Need to convert action.isArray to boolean in case it is undefined
if (angular.isArray(data) !== (!!action.isArray)) {
if (isArray(data) !== (!!action.isArray)) {
throw $resourceMinErr('badcfg',
'Error in resource configuration for action `{0}`. Expected response to ' +
'contain an {1} but got an {2} (Request: {3} {4})', name, action.isArray ? 'array' : 'object',
angular.isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url);
isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url);
}
if (action.isArray) {
value.length = 0;
@@ -768,7 +771,7 @@ angular.module('ngResource', ['ng']).
promise = promise['finally'](function() {
value.$resolved = true;
if (!isInstanceCall && cancellable) {
value.$cancelRequest = angular.noop;
value.$cancelRequest = noop;
$timeout.cancel(numericTimeoutPromise);
timeoutDeferred = numericTimeoutPromise = httpConfig.timeout = null;
}