Skip to content

Commit e273b3c

Browse files
cakesifujbdeboer
authored andcommitted
refactor($resource): fix indentation and move a method definition
Moved Resource.bind out of the actions forEach
1 parent 7bba4ca commit e273b3c

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/ngResource/resource.js

+46-46
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @description
77
*/
88

9-
/**
9+
/**
1010
* @ngdoc object
1111
* @name ngResource.$resource
1212
* @requires $http
@@ -228,46 +228,46 @@ angular.module('ngResource', ['ng']).
228228
return $parse(path)(obj);
229229
};
230230

231-
/**
232-
* We need our custom mehtod because encodeURIComponent is too aggressive and doesn't follow
233-
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
234-
* segments:
235-
* segment = *pchar
236-
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
237-
* pct-encoded = "%" HEXDIG HEXDIG
238-
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
239-
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
240-
* / "*" / "+" / "," / ";" / "="
241-
*/
242-
function encodeUriSegment(val) {
243-
return encodeUriQuery(val, true).
244-
replace(/%26/gi, '&').
245-
replace(/%3D/gi, '=').
246-
replace(/%2B/gi, '+');
247-
}
248-
249-
250-
/**
251-
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
252-
* method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
253-
* encoded per http://tools.ietf.org/html/rfc3986:
254-
* query = *( pchar / "/" / "?" )
255-
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
256-
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
257-
* pct-encoded = "%" HEXDIG HEXDIG
258-
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
259-
* / "*" / "+" / "," / ";" / "="
260-
*/
261-
function encodeUriQuery(val, pctEncodeSpaces) {
262-
return encodeURIComponent(val).
263-
replace(/%40/gi, '@').
264-
replace(/%3A/gi, ':').
265-
replace(/%24/g, '$').
266-
replace(/%2C/gi, ',').
267-
replace((pctEncodeSpaces ? null : /%20/g), '+');
268-
}
269-
270-
function Route(template, defaults) {
231+
/**
232+
* We need our custom mehtod because encodeURIComponent is too aggressive and doesn't follow
233+
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
234+
* segments:
235+
* segment = *pchar
236+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
237+
* pct-encoded = "%" HEXDIG HEXDIG
238+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
239+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
240+
* / "*" / "+" / "," / ";" / "="
241+
*/
242+
function encodeUriSegment(val) {
243+
return encodeUriQuery(val, true).
244+
replace(/%26/gi, '&').
245+
replace(/%3D/gi, '=').
246+
replace(/%2B/gi, '+');
247+
}
248+
249+
250+
/**
251+
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
252+
* method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
253+
* encoded per http://tools.ietf.org/html/rfc3986:
254+
* query = *( pchar / "/" / "?" )
255+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
256+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
257+
* pct-encoded = "%" HEXDIG HEXDIG
258+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
259+
* / "*" / "+" / "," / ";" / "="
260+
*/
261+
function encodeUriQuery(val, pctEncodeSpaces) {
262+
return encodeURIComponent(val).
263+
replace(/%40/gi, '@').
264+
replace(/%3A/gi, ':').
265+
replace(/%24/g, '$').
266+
replace(/%2C/gi, ',').
267+
replace((pctEncodeSpaces ? null : /%20/g), '+');
268+
}
269+
270+
function Route(template, defaults) {
271271
this.template = template = template + '#';
272272
this.defaults = defaults || {};
273273
var urlParams = this.urlParams = {};
@@ -396,11 +396,6 @@ angular.module('ngResource', ['ng']).
396396
};
397397

398398

399-
Resource.bind = function(additionalParamDefaults){
400-
return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
401-
};
402-
403-
404399
Resource.prototype['$' + name] = function(a1, a2, a3) {
405400
var params = extractParams(this),
406401
success = noop,
@@ -426,6 +421,11 @@ angular.module('ngResource', ['ng']).
426421
Resource[name].call(this, params, data, success, error);
427422
};
428423
});
424+
425+
Resource.bind = function(additionalParamDefaults){
426+
return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
427+
};
428+
429429
return Resource;
430430
}
431431

0 commit comments

Comments
 (0)