diff options
| author | Alkis Evlogimenos | 2010-09-15 19:27:58 +0200 |
|---|---|---|
| committer | Misko Hevery | 2010-09-16 00:23:22 +0200 |
| commit | 293f34cd64886a1dddae9c295fafde5c47029a3b (patch) | |
| tree | b1cb99e8be24eb23d39ac8aee45d531e3ee96704 /src/Resource.js | |
| parent | b798ee80c29d877aa8c9934382a140a080fa13bc (diff) | |
| download | angular.js-293f34cd64886a1dddae9c295fafde5c47029a3b.tar.bz2 | |
Expose GET operations on resources as well. This allows us to read
"partials". The pattern is demostrated in the unittest:
Resource.query returns a list of "keys" to resources, which are
partially defined. They have enough data to allow $get to fetch the
whole gamout. Then $get fetches all the details of the resource.
Diffstat (limited to 'src/Resource.js')
| -rw-r--r-- | src/Resource.js | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/Resource.js b/src/Resource.js index 85028dc1..09c09acc 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -63,7 +63,6 @@ ResourceFactory.prototype = { } foreach(actions, function(action, name){ - var isGet = action.method == 'GET'; var isPostOrPut = action.method == 'POST' || action.method == 'PUT'; Resource[name] = function (a1, a2, a3) { var params = {}; @@ -118,25 +117,23 @@ ResourceFactory.prototype = { return self.route(url, extend({}, paramDefaults, additionalParamDefaults), actions); }; - if (!isGet) { - Resource.prototype['$' + name] = function(a1, a2){ - var self = this; - var params = extractParams(self); - var callback = noop; - switch(arguments.length) { - case 2: params = a1; callback = a2; - case 1: if (typeof a1 == $function) callback = a1; else params = a1; - case 0: break; - default: - throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments."; - } - var data = isPostOrPut ? self : _undefined; - Resource[name](params, data, function(response){ - copy(response, self); - callback(self); - }); - }; - } + Resource.prototype['$' + name] = function(a1, a2){ + var self = this; + var params = extractParams(self); + var callback = noop; + switch(arguments.length) { + case 2: params = a1; callback = a2; + case 1: if (typeof a1 == $function) callback = a1; else params = a1; + case 0: break; + default: + throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments."; + } + var data = isPostOrPut ? self : _undefined; + Resource[name](params, data, function(response){ + copy(response, self); + callback(self); + }); + }; }); return Resource; } |
