cgross / generator-cg-angular

Yeoman generator for Enterprise Angular projects.
MIT License
592 stars 198 forks source link

Alternative approach to the partial generator #84

Open gabbsmo opened 10 years ago

gabbsmo commented 10 years ago

Much have happened over the years and I've found some interesting thoughts that are not yet implemented in any mainstream build systems.

Combining directives with controllerAs and isolated scope The controllerAs syntax was introduced in 1.2 and makes controller functions more vanilla JavaScript and less coupled with Angular. Putting the logic of a directive in a controller with isolated scope allows the directive to be moved around freely since it by definition don't have a dependency on the parent scope. I see this as an alternative to the current partial sub generator.

Defining controllers in closures Defining a controller function as a named JavaScript closure and then registering it with Angular's DI makes the code more readable and stack traces will be more informative.

cgross commented 10 years ago

Those are two really thought provoking blog posts. The post about using directives instead of controllers is really smart but I don't think I'm ready to dump controllers just yet. I agree with alot of those points but not sure the solution is better than the issues. Also, the "Poor View organization" is not a problem if you use this generator.

The second one is a bit less radical. Today, this generator doesn't use the controllerAs syntax but that should probably change. After that, if you choose to have your controller return an object to help isolate what is exactly on the controller, I think you could do that with little help from the generator.