olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 152 forks source link

Dot notated namespacing #223

Closed shannonhochkins closed 8 years ago

shannonhochkins commented 8 years ago

It would

Let's say I have a simple API called:

var app = angular.module('slots', []);
app.service('slots.api', function() {
   return {
      get : function() {
         return true;
      }
   }
});

I use ng-annotate in conjunction with gulp to automatically include my dependencies for minification.

However, I have recently changed the way I namespace my modules, so If I have a service that's specifically relating to the the slots module, I'll prefix it with slots.

However ng-annotate doesn't look like it supports that, is there a way to automatically do this with ng-annotate? so that the result would look something like:

app.service(['slots.api', function(api) {
    var result = api.get();
}]);
olov commented 8 years ago

Hi! I don't understand what you're proposing. Can you please provide a minimal input example together with actual ng-annotate output as well as the output you propose? Thanks.

omsmith commented 8 years ago

@olov believe this was the request

angular.module('foo').service(function (bar) {});
angular.module('foo').service(['baz.bar'], function (bar) {});

Where baz is a configured namespace of some sort.

Don't see how this would work out (if you used a third party dependency ever).

shannonhochkins commented 8 years ago

Hi @olov, yes @omsmith has the correct example that I'm trying to replicate.

Basically I'm trying to namespace my providers so that they're easier to read and we know exactly what module they belong to etc.

olov commented 8 years ago

Thanks. That seems to be outside outside of the scope for ng-annotate so I'm closing the issue.

samithaf commented 8 years ago

@olov This seems to be a valid use case. If anyone is using ng-annotate in a large Angular App they going to hit this problem.

deltaidea commented 8 years ago

Perhaps, support for such cases can be achieved by adding some sort of aliasing syntax.

How about this?

// Source
angular.module('foo').service(function (api /*ng-from slots*/) {})

// Translates to
angular.module('foo').service(['slots.api', function (api) {}])

Or this:

// Source
angular.module('foo').service(function (/*ng-as slots.api*/ api) {})

// Translates to the same
angular.module('foo').service(['slots.api', function (api) {}])

This syntax should be optional and defined per dependency:

// Source
angular.module('foo').service(function (foo /*ng-from ns*/, bar, qux /*ng-from my*/) {})

// Translates to
angular.module('foo').service(['ns.foo', 'bar', 'my.qux', function (foo, bar, qux) {}])