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

Controller.resolve versus IIFE #14

Closed
MattKetmo opened this issue Aug 16, 2014 · 6 comments
Closed

Controller.resolve versus IIFE #14

MattKetmo opened this issue Aug 16, 2014 · 6 comments

Comments

@MattKetmo
Copy link

Hello,

I just wonder how you can use the Controller.resolve property when using IIFE (assuming the routing config and the controller are in separate files).
Using tools like Browserify solves this problem, but when you simply concat all your script files I don't see a way to use a property of the controller while configuring the router.
Any recommandation?

@toddmotto
Copy link
Owner

Just use one IIFE, then all functions are in the same scope.

@MattKetmo
Copy link
Author

Indeed, that'd what you recommend in your README 😄

In fact I though about @johnpapa's styleguide where each file is wrapped with an IIFE.

I was more confident about collisions in the case you use variables out of the (main) function scope:

(function() {

var foo = 'bar';
function FooController() {
  this.foo = foo;
}
angular
  .module('app')
  .controller('FooController', FooController);

})();

but finally I don't think this is a good practice (mostly for testing purpose)

@toddmotto
Copy link
Owner

Each file for me is an overkill, there isn't really need to and it gets a bit repetitive unless automated. Variables would be part of presentational logic if anything, therefore quite unique - just like the CSS we write, none of it should conflict with other parts of the app :)

If you've got 1000 JavaScript files, 999 extra function calls isn't necessary either!

@fredbliss
Copy link

Agreed with @toddmotto - I don't believe in bloating code with safeguards that would be avoidable using overhead-free best practices. A good variable naming convention could accomplish the same, in my opinion.

@johnpapa
Copy link

automation makes this easy to remove if you need to. and if this is the biggest problem your app has, then you are in great shape. :)

If you run locally in non automated mode (which a lot of devs do) the IIFE's give you a a truer sense of the global isolation than if you just avoid them.

I use a template/snippet, and there are no slowdowns.

Again, this is not a big deal as long as you do protect yourself in some way

@MattKetmo
Copy link
Author

Ok, interesting point of view. Indeed, it's not a big deal, and there is not a single way to manage scripts compilation.

Thanks for your answers

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

4 participants