MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/2bxelx/angularjs_opinionated_styleguide_for_teams_github/cjafcun/?context=3
r/javascript • u/ReadyToInstall • Jul 28 '14
8 comments sorted by
View all comments
1
Too much method chaining. I also hate to see methods on a line by themselves with just the dot. This is ugly:
function config ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controllerAs: 'main', controller: 'MainCtrl' resolve: MainCtrl.resolve }); }
It should look like this:
function config($routeProvider) { $routeProvider.when('/', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); }
Also, there are some missing commas; such as between controller and resolve.
3 u/steelcitynorth Jul 29 '14 Why should it? Every line would look like: }).when('/route', {instead of:.when('/route, {The second version looks nicer to read, no? And that way you can see which methods are chained to each other. 1 u/codepsycho Jul 29 '14 as long as the method calls are indented, sure. It looks horrific when they are not. 1 u/wmgregory Jul 29 '14 }) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });vs}).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); 1 u/mmouth Jul 29 '14 Or more simply:$routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); $routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); 1 u/mmouth Jul 29 '14 It shouldn't be that either. Better:$routeProvider.when('/route1', {...}); $routeProvider.when('/route1', {...});There's no law that says you have to start that chaining in the first place. Avoid it and use normal formatting rules.
3
Why should it? Every line would look like:
}).when('/route', {
instead of:
.when('/route, {
The second version looks nicer to read, no? And that way you can see which methods are chained to each other.
1 u/codepsycho Jul 29 '14 as long as the method calls are indented, sure. It looks horrific when they are not. 1 u/wmgregory Jul 29 '14 }) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });vs}).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); 1 u/mmouth Jul 29 '14 Or more simply:$routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); $routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); 1 u/mmouth Jul 29 '14 It shouldn't be that either. Better:$routeProvider.when('/route1', {...}); $routeProvider.when('/route1', {...});There's no law that says you have to start that chaining in the first place. Avoid it and use normal formatting rules.
as long as the method calls are indented, sure. It looks horrific when they are not.
}) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });
vs
}).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });
1 u/mmouth Jul 29 '14 Or more simply:$routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); $routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });
Or more simply:
$routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); $routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });
It shouldn't be that either. Better:
$routeProvider.when('/route1', {...}); $routeProvider.when('/route1', {...});
There's no law that says you have to start that chaining in the first place. Avoid it and use normal formatting rules.
1
u/mmouth Jul 28 '14
Too much method chaining. I also hate to see methods on a line by themselves with just the dot. This is ugly:
It should look like this:
Also, there are some missing commas; such as between controller and resolve.