Hi guys!

Quick question about $resources.  Currently in the app that I'm building I 
have a file that defines all my $resources, in this format:

app.factory('Recruiter', ['$resource', function($resource) {
  return $resource('/api/recruiters/:id.json', null,
    {
        'update': { method:'PATCH' },
        'search': { method:'PATCH', isArray: true }
    });
}]);

I have multiple controllers throughout the app ( 12-15 ) that each use 
these resources.  I'm looking into Angular Services to DRY up my 
controllers and came up with a service that I could inject into every 
controller for say, destroying a specific resource.  A destroyRecruiter 
service for instance.  That worked fine, but I wanted to see if I could 
further DRY this up.  So I came with with a destroyResource service:

app.service('sharedDestroy', function($resource, $q){
  var deferred = $q.defer();
  this.destroyResource = function(string, resource, resourceCollection){
    obj = $resource("/api/"+string+"/:id.json", {id:resource.id});
    obj.delete({}, function(){
      var index = resourceCollection.indexOf(resource);
      resourceCollection.splice(index, 1);
      deferred.resolve(resourceCollection);
    },function(err){
      deferred.reject(err);
    });
    return deferred.promise;
  }
});

My question is this.  Are there any performance draw backs with creating a 
resource on the fly like this for every destroy call?  Is this excessive? 
 Also, feel free to tell me that this is a terrible idea, wont hurt my 
feelings.  Ive been developing with Angular for about 2 months now and im 
still learning the ins and outs.  I appreciate any comments/feedback!!

Thanks a bunch,
Josh

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to