Usage of IIFE pattern
The IIFE pattern would be very useful to have within the generator. Is this pattern left out on purpose, for what reason?
We do use them, for ex in admin.controller.js. IIFEs are useful for preventing references from polluting the global scope of the browser. If we're not concerned with something polluting the global scope, there's no point in using an IIFE. Using IIFEs for makeshift modules isn't a good practice nowadays also.
Yes I do agree that IIFE is very useful as an extra prevention step, that's why I consider it as very important pattern. You are referring to the admin.controller.js where the pattern is being used, but my question is more referring auto-usage of this pattern when for instance generating a service/controller I think it would be good have IIFE generated within the code skeleton. What's your opinon regarding this case?
Could you give a code example of what you're referring to?
if I run:
yo angular-fullstack:service myService
then I would like to get something like:
(function() {
'use strict';
angular.module('myApp')
.service('myService', function () {
// AngularJS will instantiate a singleton by calling "new" on this function
});
})();
Agree with @sedina because several parts already covered with IIFE (see out-of-box main controller implementation).
'use strict';
(function() {
function MainController($scope) {
}
angular.module('app')
.controller('MainController', MainController);
})();
Would be good to have consistency in every module.
Yeah, @sedina in your example I don't see a point in using an IIFE there, since you're not instantiating any variables that would be attached to the global scope / window there. Also note, the client-side subgenerators (such as the service generator) are not part of this project, but imported from generator-ng-component.
@donvadicastro your example could warrant an IIFE. It's not too likely that a variable named MainController would collide, but better safe than sorry I guess? There are a few more spots that could use it.