Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngResource gets incorrectly wrapped into a function aspect #12

Closed
valir opened this issue Aug 31, 2014 · 2 comments
Closed

ngResource gets incorrectly wrapped into a function aspect #12

valir opened this issue Aug 31, 2014 · 2 comments

Comments

@valir
Copy link

valir commented Aug 31, 2014

I'm using angular-aop to put an around advice for the ngResource I use to call server-side API. Like this:

myServices.factory('WelcomeService', [ '$resource', 'execute', 'MyAroundAspect', 
      function($resource, execute, ServerCommState ) {
          return execute(MyAroundAspect).around( $resource('/api/welcome/:id', {
              id: '@id'
          }, {
              create: {
                  method: 'POST',
                  params: {
                      nick: '@nick'
                  }   
              },  
              update: {
                  method: 'PUT'
              }
          }));
      }
  ]);

When calling this service's get method, I get an undefined exception, unless I modify angular-aop.js like this:

  //Builds specified aspect
  AspectBuilder = { 
      buildAspect: function (advice, pointcut) {
        var self = this;
        return function (target, rules) {
          // if (typeof target === 'function') {
          //   return self._getFunctionAspect(target, pointcut, advice);
          // } else if (target) {
            return self._getObjectAspect(target, rules || {}, pointcut, advice);
          // }
        };  
      },  

As you may see, I modify the code so buildAspect always return an object aspect. With this modification, the MyAroundAspect gets called, twice per service call.

My solution is not an ideal one, but I'm not using function aspects, so that's fine for me. However, what should be done in order to enable AOP for ngResource without disabling function advices ?

@valir valir changed the title ngResource is gets incorrectly wrapped into a function aspect ngResource gets incorrectly wrapped into a function aspect Aug 31, 2014
@mgechev
Copy link
Owner

mgechev commented Sep 3, 2014

Thanks for the issue. I'll take a look asap!

@mgechev
Copy link
Owner

mgechev commented Sep 8, 2014

I reviewed the issue. Since $resource is a function with methods, the _getFunctionAspect method is being invoked.

I'll extend the API by adding a property, which forces the framework to wrap the function's methods.

@mgechev mgechev closed this as completed in b6a8a59 Sep 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants