aleross / angular-segment-analytics

AngularJS module for easily adding Segment analytics to any app. https://segment.com
MIT License
43 stars 14 forks source link

Unable to use condition with minification #16

Closed stwiname closed 8 years ago

stwiname commented 8 years ago

I'm getting injector errors when trying to set the condition. What I have is;

condition: ($rootScope) => {
  return $rootScope.isProduction;
}

But when it gets minified $rootScope gets replaced with some arbitrary character. This causes Angular to have injector problems.

It would be nice if we could rely on stricter Angular DI. Being able to do this would be nice:

condition: ['$rootScope', ($rootScope) => {
 return $rootScope.isProduction;
}]

But that then throws Condition callback must be a function

aleross commented 8 years ago

Thanks for opening this ticket @stwiname. I agree strict DI would be a good improvement so that files using a condition can be minified.

If you or anybody else is interested in making the changes, there are (at least) two places that would need to be adjusted:

  1. The validation method src/provider.js#L174
  2. The point where the user-provided condition function is injected with dependencies by Angular's $injector service src/provider.js#L218

These could both be modified to check for either a function or Array with two params of correct types. And we'd need to make sure Angular's $injector service works with strict DI arrays correctly.

aleross commented 8 years ago

Merged and released in v1.2.0, thanks @stwiname!