diff options
| author | Alkis Evlogimenos | 2010-09-22 09:11:36 +0200 | 
|---|---|---|
| committer | Misko Hevery | 2010-09-22 09:14:50 +0200 | 
| commit | eefb920d0e0345485a8eb120aeecc3b1aa9f6719 (patch) | |
| tree | dfdabdebb82cba116b4d222af1e3a81cf46f54b0 | |
| parent | 006fd2ca252400e87a419b929e00ea0277ff86ad (diff) | |
| download | angular.js-eefb920d0e0345485a8eb120aeecc3b1aa9f6719.tar.bz2 | |
Reduce copies done by Resource.
When a method foo is called on a Resource object, say myResource there are two copies that happen to the resource:
	- one inside Resource.foo() in some dummy function
	- another inside myResource.$foo() inside the callback passed to foo()
| -rw-r--r-- | src/Resource.js | 12 | 
1 files changed, 4 insertions, 8 deletions
| diff --git a/src/Resource.js b/src/Resource.js index 09c09acc..bab1b800 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -88,7 +88,7 @@ ResourceFactory.prototype = {            throw "Expected between 0-3 arguments [params, data, callback], got " + arguments.length + " arguments.";          } -        var value = action.isArray ? [] : new Resource(data); +        var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));          self.xhr(            action.method,            route.url(extend({}, action.params || {}, extractParams(data), params)), @@ -118,8 +118,7 @@ ResourceFactory.prototype = {        };        Resource.prototype['$' + name] = function(a1, a2){ -        var self = this; -        var params = extractParams(self); +        var params = extractParams(this);          var callback = noop;          switch(arguments.length) {          case 2: params = a1; callback = a2; @@ -128,11 +127,8 @@ ResourceFactory.prototype = {          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); -        }); +        var data = isPostOrPut ? this : _undefined; +        Resource[name].call(this, params, data, callback);        };      });      return Resource; | 
