From 293f34cd64886a1dddae9c295fafde5c47029a3b Mon Sep 17 00:00:00 2001 From: Alkis Evlogimenos Date: Wed, 15 Sep 2010 19:27:58 +0200 Subject: 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. --- src/Resource.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3